Best JavaScript code snippet using storybook-root
day7_input.py
Source:day7_input.py
1test_step = """Step C must be finished before step A can begin.2Step C must be finished before step F can begin.3Step A must be finished before step B can begin.4Step A must be finished before step D can begin.5Step B must be finished before step E can begin.6Step D must be finished before step E can begin.7Step F must be finished before step E can begin."""8real_step = """Step F must be finished before step P can begin.9Step R must be finished before step J can begin.10Step X must be finished before step H can begin.11Step L must be finished before step N can begin.12Step U must be finished before step Z can begin.13Step B must be finished before step C can begin.14Step S must be finished before step C can begin.15Step N must be finished before step Y can begin.16Step I must be finished before step J can begin.17Step H must be finished before step K can begin.18Step G must be finished before step Z can begin.19Step Q must be finished before step V can begin.20Step E must be finished before step P can begin.21Step P must be finished before step W can begin.22Step J must be finished before step D can begin.23Step V must be finished before step W can begin.24Step T must be finished before step D can begin.25Step Z must be finished before step A can begin.26Step K must be finished before step A can begin.27Step Y must be finished before step O can begin.28Step O must be finished before step W can begin.29Step C must be finished before step M can begin.30Step D must be finished before step A can begin.31Step W must be finished before step M can begin.32Step M must be finished before step A can begin.33Step C must be finished before step A can begin.34Step F must be finished before step Z can begin.35Step I must be finished before step A can begin.36Step W must be finished before step A can begin.37Step T must be finished before step C can begin.38Step S must be finished before step K can begin.39Step B must be finished before step J can begin.40Step O must be finished before step A can begin.41Step Q must be finished before step P can begin.42Step G must be finished before step M can begin.43Step R must be finished before step T can begin.44Step B must be finished before step G can begin.45Step J must be finished before step O can begin.46Step X must be finished before step E can begin.47Step X must be finished before step C can begin.48Step H must be finished before step Y can begin.49Step Y must be finished before step A can begin.50Step X must be finished before step W can begin.51Step H must be finished before step A can begin.52Step X must be finished before step A can begin.53Step I must be finished before step M can begin.54Step G must be finished before step J can begin.55Step N must be finished before step G can begin.56Step D must be finished before step M can begin.57Step L must be finished before step D can begin.58Step V must be finished before step T can begin.59Step I must be finished before step Y can begin.60Step S must be finished before step J can begin.61Step K must be finished before step Y can begin.62Step F must be finished before step R can begin.63Step U must be finished before step T can begin.64Step Z must be finished before step M can begin.65Step T must be finished before step Z can begin.66Step B must be finished before step I can begin.67Step E must be finished before step K can begin.68Step N must be finished before step J can begin.69Step X must be finished before step Q can begin.70Step F must be finished before step Y can begin.71Step H must be finished before step P can begin.72Step Z must be finished before step D can begin.73Step V must be finished before step O can begin.74Step E must be finished before step C can begin.75Step V must be finished before step C can begin.76Step P must be finished before step A can begin.77Step B must be finished before step N can begin.78Step S must be finished before step W can begin.79Step P must be finished before step D can begin.80Step L must be finished before step W can begin.81Step D must be finished before step W can begin.82Step K must be finished before step C can begin.83Step L must be finished before step M can begin.84Step R must be finished before step O can begin.85Step F must be finished before step L can begin.86Step R must be finished before step H can begin.87Step K must be finished before step O can begin.88Step T must be finished before step W can begin.89Step R must be finished before step K can begin.90Step C must be finished before step W can begin.91Step N must be finished before step T can begin.92Step R must be finished before step P can begin.93Step E must be finished before step M can begin.94Step G must be finished before step T can begin.95Step U must be finished before step K can begin.96Step Q must be finished before step D can begin.97Step U must be finished before step S can begin.98Step J must be finished before step V can begin.99Step P must be finished before step Y can begin.100Step X must be finished before step Z can begin.101Step U must be finished before step H can begin.102Step H must be finished before step M can begin.103Step I must be finished before step C can begin.104Step V must be finished before step M can begin.105Step N must be finished before step I can begin.106Step B must be finished before step K can begin.107Step R must be finished before step Q can begin.108Step O must be finished before step C can begin."""109step_list = real_step.splitlines()110adjustment = 60111alpha_value = {112 "A": 1 + adjustment,113 "B": 2 + adjustment,114 "C": 3 + adjustment,115 "D": 4 + adjustment,116 "E": 5 + adjustment,117 "F": 6 + adjustment,118 "G": 7 + adjustment,119 "H": 8 + adjustment,120 "I": 9 + adjustment,121 "J": 10 + adjustment,122 "K": 11 + adjustment,123 "L": 12 + adjustment,124 "M": 13 + adjustment,125 "N": 14 + adjustment,126 "O": 15 + adjustment,127 "P": 16 + adjustment,128 "Q": 17 + adjustment,129 "R": 18 + adjustment,130 "S": 19 + adjustment,131 "T": 20 + adjustment,132 "U": 21 + adjustment,133 "V": 22 + adjustment,134 "W": 23 + adjustment,135 "X": 24 + adjustment,136 "Y": 25 + adjustment,137 "Z": 26 + adjustment,...
test_target.py
Source:test_target.py
1"""2 weasyprint.tests.test_target3 ----------------------------4 Test the CSS cross references using target-*() functions.5"""6from .testing_utils import FakeHTML, assert_no_logs7@assert_no_logs8def test_target_counter():9 document = FakeHTML(string='''10 <style>11 div:first-child { counter-reset: div }12 div { counter-increment: div }13 #id1::before { content: target-counter('#id4', div) }14 #id2::before { content: 'test ' target-counter('#id1' div) }15 #id3::before { content: target-counter(url(#id4), div, lower-roman) }16 #id4::before { content: target-counter('#id3', div) }17 </style>18 <body>19 <div id="id1"></div>20 <div id="id2"></div>21 <div id="id3"></div>22 <div id="id4"></div>23 ''')24 page, = document.render().pages25 html, = page._page_box.children26 body, = html.children27 div1, div2, div3, div4 = body.children28 before = div1.children[0].children[0].children[0]29 assert before.text == '4'30 before = div2.children[0].children[0].children[0]31 assert before.text == 'test 1'32 before = div3.children[0].children[0].children[0]33 assert before.text == 'iv'34 before = div4.children[0].children[0].children[0]35 assert before.text == '3'36@assert_no_logs37def test_target_counter_attr():38 document = FakeHTML(string='''39 <style>40 div:first-child { counter-reset: div }41 div { counter-increment: div }42 div::before { content: target-counter(attr(data-count), div) }43 #id2::before { content: target-counter(attr(data-count, url), div) }44 #id4::before {45 content: target-counter(attr(data-count), div, lower-alpha) }46 </style>47 <body>48 <div id="id1" data-count="#id4"></div>49 <div id="id2" data-count="#id1"></div>50 <div id="id3" data-count="#id2"></div>51 <div id="id4" data-count="#id3"></div>52 ''')53 page, = document.render().pages54 html, = page._page_box.children55 body, = html.children56 div1, div2, div3, div4 = body.children57 before = div1.children[0].children[0].children[0]58 assert before.text == '4'59 before = div2.children[0].children[0].children[0]60 assert before.text == '1'61 before = div3.children[0].children[0].children[0]62 assert before.text == '2'63 before = div4.children[0].children[0].children[0]64 assert before.text == 'c'65@assert_no_logs66def test_target_counters():67 document = FakeHTML(string='''68 <style>69 div:first-child { counter-reset: div }70 div { counter-increment: div }71 #id1-2::before { content: target-counters('#id4-2', div, '.') }72 #id2-1::before { content: target-counters(url(#id3), div, '++') }73 #id3::before {74 content: target-counters('#id2-1', div, '.', lower-alpha) }75 #id4-2::before {76 content: target-counters(attr(data-count, url), div, '') }77 </style>78 <body>79 <div id="id1"><div></div><div id="id1-2"></div></div>80 <div id="id2"><div id="id2-1"></div><div></div></div>81 <div id="id3"></div>82 <div id="id4">83 <div></div><div id="id4-2" data-count="#id1-2"></div>84 </div>85 ''')86 page, = document.render().pages87 html, = page._page_box.children88 body, = html.children89 div1, div2, div3, div4 = body.children90 before = div1.children[1].children[0].children[0].children[0]91 assert before.text == '4.2'92 before = div2.children[0].children[0].children[0].children[0]93 assert before.text == '3'94 before = div3.children[0].children[0].children[0]95 assert before.text == 'b.a'96 before = div4.children[1].children[0].children[0].children[0]97 assert before.text == '12'98@assert_no_logs99def test_target_text():100 document = FakeHTML(string='''101 <style>102 a { display: block; color: red }103 div:first-child { counter-reset: div }104 div { counter-increment: div }105 #id2::before { content: 'wow' }106 #link1::before { content: 'test ' target-text('#id4') }107 #link2::before { content: target-text(attr(data-count, url), before) }108 #link3::before { content: target-text('#id3', after) }109 #link4::before { content: target-text(url(#id1), first-letter) }110 </style>111 <body>112 <a id="link1"></a>113 <div id="id1">1 Chapter 1</div>114 <a id="link2" data-count="#id2"></a>115 <div id="id2">2 Chapter 2</div>116 <div id="id3">3 Chapter 3</div>117 <a id="link3"></a>118 <div id="id4">4 Chapter 4</div>119 <a id="link4"></a>120 ''')121 page, = document.render().pages122 html, = page._page_box.children123 body, = html.children124 a1, div1, a2, div2, div3, a3, div4, a4 = body.children125 before = a1.children[0].children[0].children[0]126 assert before.text == 'test 4 Chapter 4'127 before = a2.children[0].children[0].children[0]128 assert before.text == 'wow'129 assert len(a3.children[0].children[0].children) == 0130 before = a4.children[0].children[0].children[0]131 assert before.text == '1'132@assert_no_logs133def test_target_float():134 document = FakeHTML(string='''135 <style>136 a::after {137 content: target-counter('#h', page);138 float: right;139 }140 </style>141 <div><a id="span">link</a></div>142 <h1 id="h">abc</h1>143 ''')144 page, = document.render().pages145 html, = page._page_box.children146 body, = html.children147 div, h1 = body.children148 line, = div.children149 inline, = line.children150 text_box, after = inline.children151 assert text_box.text == 'link'...
cy.py
Source:cy.py
1# -*- coding: utf-8 -*-2info = {3 "%spellout-cardinal-feminine": {4 "0": "dim;",5 "1": "un;",6 "2": "dwy;",7 "3": "tair;",8 "4": "pedair;",9 "5": "pump;",10 "6": "chwech;",11 "7": "saith;",12 "8": "wyth;",13 "9": "naw;",14 "(10, 19)": "un deg[ >>];",15 "(20, 29)": "dau ddeg[ >>];",16 "(30, 99)": "<%spellout-cardinal-masculine-before-consonant< deg[ >>];",17 "(100, 999)": "<%spellout-cardinal-masculine-before-consonant< cant[ >>];",18 "(1000, 999999)": "<%spellout-cardinal-masculine-before-consonant< mil[ >>];",19 "(1000000, 999999999)": "<%spellout-cardinal-masculine-before-consonant< miliwn[ >>];",20 "(1000000000, 999999999999)": "<%spellout-cardinal-masculine-before-consonant< biliwn[ >>];",21 "(1000000000000, 999999999999999)": "<%spellout-cardinal-masculine-before-consonant< triliwn[ >>];",22 "(1000000000000000, 999999999999999999)": "<%spellout-cardinal-masculine-before-consonant< kwadriliwn[ >>];",23 "(1000000000000000000, 'inf')": "=#,##0=;"24 },25 "%spellout-cardinal-feminine-before-consonant": {26 "0": "dim;",27 "1": "un;",28 "2": "dwy;",29 "3": "tair;",30 "4": "pedair;",31 "5": "pum;",32 "6": "chwe;",33 "7": "saith;",34 "8": "wyth;",35 "9": "naw;",36 "(10, 19)": "un deg[ >>];",37 "(20, 29)": "dau ddeg[ >>];",38 "(30, 99)": "<%spellout-cardinal-masculine-before-consonant< deg[ >>];",39 "(100, 999)": "<%spellout-cardinal-masculine-before-consonant< cant[ >>];",40 "(1000, 999999)": "<%spellout-cardinal-masculine-before-consonant< mil[ >>];",41 "(1000000, 999999999)": "<%spellout-cardinal-masculine-before-consonant< miliwn[ >>];",42 "(1000000000, 999999999999)": "<%spellout-cardinal-masculine-before-consonant< biliwn[ >>];",43 "(1000000000000, 999999999999999)": "<%spellout-cardinal-masculine-before-consonant< triliwn[ >>];",44 "(1000000000000000, 999999999999999999)": "<%spellout-cardinal-masculine-before-consonant< kwadriliwn[ >>];",45 "(1000000000000000000, 'inf')": "=#,##0=;"46 },47 "%spellout-cardinal-masculine": {48 "0": "dim;",49 "1": "un;",50 "2": "dau;",51 "3": "tri;",52 "4": "pedwar;",53 "5": "pump;",54 "6": "chwech;",55 "7": "saith;",56 "8": "wyth;",57 "9": "naw;",58 "(10, 19)": "un deg[ >>];",59 "(20, 29)": "dau ddeg[ >>];",60 "(30, 99)": "<%spellout-cardinal-masculine-before-consonant< deg[ >>];",61 "(100, 999)": "<%spellout-cardinal-masculine-before-consonant< cant[ >>];",62 "(1000, 999999)": "<%spellout-cardinal-masculine-before-consonant< mil[ >>];",63 "(1000000, 999999999)": "<%spellout-cardinal-masculine-before-consonant< miliwn[ >>];",64 "(1000000000, 999999999999)": "<%spellout-cardinal-masculine-before-consonant< biliwn[ >>];",65 "(1000000000000, 999999999999999)": "<%spellout-cardinal-masculine-before-consonant< triliwn[ >>];",66 "(1000000000000000, 999999999999999999)": "<%spellout-cardinal-masculine-before-consonant< kwadriliwn[ >>];",67 "(1000000000000000000, 'inf')": "=#,##0=;"68 },69 "%spellout-cardinal-masculine-before-consonant": {70 "0": "dim;",71 "1": "un;",72 "2": "dau;",73 "3": "tri;",74 "4": "pedwar;",75 "5": "pum;",76 "6": "chwe;",77 "7": "saith;",78 "8": "wyth;",79 "9": "naw;",80 "(10, 19)": "un deg[ >>];",81 "(20, 29)": "dau ddeg[ >>];",82 "(30, 99)": "<%spellout-cardinal-masculine-before-consonant< deg[ >>];",83 "(100, 999)": "<%spellout-cardinal-masculine-before-consonant< cant[ >>];",84 "(1000, 999999)": "<%spellout-cardinal-masculine-before-consonant< mil[ >>];",85 "(1000000, 999999999)": "<%spellout-cardinal-masculine-before-consonant< miliwn[ >>];",86 "(1000000000, 999999999999)": "<%spellout-cardinal-masculine-before-consonant< biliwn[ >>];",87 "(1000000000000, 999999999999999)": "<%spellout-cardinal-masculine-before-consonant< triliwn[ >>];",88 "(1000000000000000, 999999999999999999)": "<%spellout-cardinal-masculine-before-consonant< kwadriliwn[ >>];",89 "(1000000000000000000, 'inf')": "=#,##0=;"90 },91 "%spellout-numbering": {92 "(0, 'inf')": "=%spellout-cardinal-masculine=;"93 },94 "%spellout-numbering-year": {95 "(0, 'inf')": "=%spellout-numbering=;"96 }...
moodRatingTime.py
Source:moodRatingTime.py
1import pandas2import matplotlib.pyplot as plt3import numpy as np4import math5import cv26from PIL import Image7import datetime8df = pandas.read_csv('../data/moodLogFinal.csv')9df2after = pandas.read_csv('../data/moodLogFinalAfter.csv')10# 22. april 16.46 shift from no light control to light control11getEnergy = True12def reverse(n): 13 return 160 - n14timestamps = df["Timestamp"]15if(getEnergy):16 energyLevel = df["y"]17 energyLevel = map(reverse, energyLevel)18else:19 energyLevel = df["x"]20minutes = []21timestampsAfter = df2after["Timestamp"]22if(getEnergy):23 energyLevelAfter = df2after["y"]24 energyLevelAfter = map(reverse, energyLevelAfter)25else:26 energyLevelAfter = df2after["x"]27minutesAfter = []28for i in range(len(df)):29 date = datetime.datetime.fromtimestamp(df['Timestamp'][i] / 1e3)30 thisMinute = int(date.strftime("%M"))31 thisHour = int(date.strftime("%H"))32 minute = thisHour * 60 + thisMinute33 minutes.append(minute)34for i in range(len(df2after)):35 date = datetime.datetime.fromtimestamp(df['Timestamp'][i] / 1e3)36 thisMinute = int(date.strftime("%M"))37 thisHour = int(date.strftime("%H"))38 minute = thisHour * 60 + thisMinute39 minutesAfter.append(minute)40# AVG morning before41avgMorningBefore = 042avgMorningBeforeEnergy = 043counter = 044counter2 = 045while(counter < len(minutes)):46 if(minutes[counter] < 800):47 avgMorningBefore = avgMorningBefore + minutes[counter]48 avgMorningBeforeEnergy = avgMorningBeforeEnergy + energyLevel[counter]49 counter2 = counter2 + 150 counter = counter + 151avgMorningBefore = avgMorningBefore / counter252avgMorningBeforeEnergy = avgMorningBeforeEnergy / counter253# AVG evening before54avgEveningBefore = 055avgEveningBeforeEnergy = 056counter = 057counter2 = 058while(counter < len(minutes)):59 if(minutes[counter] > 800):60 avgEveningBefore = avgEveningBefore + minutes[counter]61 avgEveningBeforeEnergy = avgEveningBeforeEnergy + energyLevel[counter]62 counter2 = counter2 + 163 counter = counter + 164 print(counter2)65avgEveningBefore = avgEveningBefore / counter266avgEveningBeforeEnergy = avgEveningBeforeEnergy / counter267print(avgMorningBefore, avgMorningBeforeEnergy)68 69# AVG morning after70avgMorningAfter = 071avgMorningAfterEnergy = 072counter = 073counter2 = 074while(counter < len(minutesAfter)):75 if(minutes[counter] < 800):76 avgMorningAfter = avgMorningAfter + minutesAfter[counter]77 avgMorningAfterEnergy = avgMorningAfterEnergy + energyLevelAfter[counter]78 counter2 = counter2 + 179 counter = counter + 180avgMorningAfter = avgMorningAfter / counter281avgMorningAfterEnergy = avgMorningAfterEnergy / counter282# AVG evening after83avgEveningAfter = 084avgEveningAfterEnergy = 085counter = 086counter2 = 087while(counter < len(minutesAfter)):88 if(minutes[counter] > 800):89 avgEveningAfter = avgEveningAfter + minutesAfter[counter]90 avgEveningAfterEnergy = avgEveningAfterEnergy + energyLevelAfter[counter]91 counter2 = counter2 + 192 counter = counter + 193avgEveningAfter = avgEveningAfter / counter294avgEveningAfterEnergy = avgEveningAfterEnergy / counter295# From 0 to 16096area = np.pi*597# Plot98plt.grid(color='#eeeeee', linestyle='-', linewidth=1)99plt.scatter(minutes, energyLevel, s=area, color="#ff4040", label="Before")100plt.scatter(minutesAfter, energyLevelAfter, s=area, color="#4040ff", label="After")101#plt.scatter(avgMorningBefore, avgMorningBeforeEnergy, s=area, color="#00ff00", label="Before avg")102#plt.scatter(avgEveningBefore, avgEveningBeforeEnergy, s=area, color="#00ff00", label="Before avg")103#plt.scatter(avgMorningAfter, avgMorningAfterEnergy, s=area, color="#ffff00", label="After avg")104#plt.scatter(avgEveningAfter, avgEveningAfterEnergy, s=area, color="#ffff00", label="After avg")105plt.plot([avgMorningBefore, avgEveningBefore], [avgMorningBeforeEnergy, avgEveningBeforeEnergy], color="#ff4040", label="Before (avg)")106plt.plot([avgMorningAfter, avgEveningAfter], [avgMorningAfterEnergy, avgEveningAfterEnergy], color="#4040ff", label="After (avg)")107plt.title('Time of mood rating and energy level')108plt.xlabel('Time of day in minutes')109if(getEnergy):110 plt.ylabel('Energy level')111else:112 plt.ylabel('Happiness')113plt.ylim(0, 160)114plt.legend()...
test_bits.py
Source:test_bits.py
...86 assert_equal(b.after(45), 50)87 assert_equal(b.after(47), 50)88 assert_equal(b.after(50), 80)89 assert_equal(b.after(80), None)90 assert_equal(b.before(0), None)91 assert_equal(b.before(99), 80)92 assert_equal(b.before(81), 80)93 assert_equal(b.before(80), 50)94 assert_equal(b.before(50), 30)95 assert_equal(b.before(48), 30)96 assert_equal(b.before(46), 30)97 assert_equal(b.before(45), 30)98 assert_equal(b.before(44), 30)99 assert_equal(b.before(42), 30)100 assert_equal(b.before(38), 30)101 assert_equal(b.before(36), 30)102 assert_equal(b.before(34), 30)103 assert_equal(b.before(33), 30)104 assert_equal(b.before(32), 30)105 assert_equal(b.before(30), 11)106 assert_equal(b.before(11), 10)107 assert_equal(b.before(10), None)108 b = c([7])109 assert_equal(b.after(0), 7)110 b = c([8])111 assert_equal(b.after(0), 8)112 b = c([9])113 assert_equal(b.after(0), 9)114 b = c([7])115 assert_equal(b.before(16), 7)116 b = c([8])117 assert_equal(b.before(16), 8)118 b = c([9])119 assert_equal(b.before(16), 9)120 b = c([49])121 assert_equal(b.after(0), 49)122def test_sortedintset():123 test_bit_basics(SortedIntSet)124 test_len(SortedIntSet)125 test_union(SortedIntSet)126 test_intersection(SortedIntSet)127 test_difference(SortedIntSet)128 test_copy(SortedIntSet)129 test_clear(SortedIntSet)130 test_isdisjoint(SortedIntSet)...
final_p8.py
Source:final_p8.py
1class Frob(object):2 def __init__(self, name):3 self.name = name4 self.before = None5 self.after = None6 def setBefore(self, before):7 self.before = before8 def setAfter(self, after):9 self.after = after10 def getBefore(self):11 return self.before12 def getAfter(self):13 return self.after14 def myName(self):15 return self.name16 def __repr__(self):17 before = self.getBefore()18 before = before.myName() if before else '*'19 me = self.name.upper()20 after = self.getAfter()21 after = after.myName() if after else '*'22 return '%s--%s--%s' % (before, me, after)23def get_ins_pos(p, q):24 # FIXME: should return a ternary.25 '''Return new pair of Frobs to mutate.26 27 p: current Frob.28 q: new Frob to insert.29 '''30 # To put q before p31 if q.myName() < p.myName():32 # p does not have a head33 if p.getBefore() is None:34 return (q, p)35 # p has a head36 else:37 return get_ins_pos(p.getBefore(), q)38 # To put q after p39 else:40 # p does not have a tail41 if p.getAfter() is None:42 return (p, q)43 else:44 return get_ins_pos(p.getAfter(), q)45def get_ins_pos_bisect(p, l):46 '''Return a ternary of Frobs to mutate in the order they are to be47 appearing in the linkedlist.48 49 p: current Frob.50 q: new Frob to insert.51 '''52 from bisect import bisect53 bisect(p)54def insert(atMe, newFrob):55 """56 atMe: a Frob that is part of a doubly linked list57 newFrob: a Frob with no links58 This procedure appropriately inserts newFrob into the linked list that atMe59 is a part of. 60 """61 from bisect import bisect62 p, q = atMe, newFrob63 frobs = get_all_frobs(p)64 frob_names = [f.myName() for f in frobs]65 index = bisect(frob_names, q.myName())66 frobs.insert(index, q)67 #print index68 #print len(frobs)69 try:70 p = frobs[index - 1]71 except IndexError:72 p = None73 c = frobs[index]74 try:75 q = frobs[index + 1]76 except IndexError:77 q = None78 #print p, c, q79 # FIXME: this is buggy. But I quit here. Jun 1 201380 p.setAfter(c)81 c.setBefore(p)82 c.setAfter(q)83 q.setBefore(c)84 #b, a = get_ins_pos(atMe, newFrob)85 #b.setAfter(a)86 #a.setBefore(b)87def get_all_frobs(f):88 from collections import deque89 l = deque([f])90 b = f.getBefore()91 # Not at the head of the linkedlist92 while b is not None:93 l.appendleft(b)94 b = b.getBefore()95 a = f.getAfter()96 while a is not None:97 l.append(a)98 a = a.getAfter()99 return list(l)100def findFront(start):101 """102 start: a Frob that is part of a doubly linked list103 returns: the Frob at the beginning of the linked list 104 """105 if start.getBefore() is None:106 return start107 else:108 return findFront(start.getBefore())109if __name__ == '__main__':110 eric = Frob('eric')111 andrew = Frob('andrew')112 ruth = Frob('ruth')113 fred = Frob('fred')114 martha = Frob('martha')115 zed = Frob('zed')116 def print_list():117 for frob in andrew, eric, fred, martha, ruth, zed:118 print frob119 insert(eric, andrew)120 print_list()121 insert(eric, ruth)122 print_list()123 #insert(eric, fred)124 #print_list()125 #insert(ruth, martha)126 #print_list()127 #insert(andrew, zed)128 #print_list()129 print '***'130 #print findFront(ruth)...
moodBoxPlot.py
Source:moodBoxPlot.py
1import pandas2import matplotlib.pyplot as plt3import numpy as np4import math5import cv26from PIL import Image7import datetime8df = pandas.read_csv('../data/moodLogFinal.csv')9df2after = pandas.read_csv('../data/moodLogFinalAfter.csv')10# 22. april 16.46 shift from no light control to light control11getEnergy = True12def reverse(n): 13 return 160 - n14timestamps = df["Timestamp"]15energyLevel = df["y"]16energyLevel = map(reverse, energyLevel)17happinessLevel = df["x"]18minutes = []19timestampsAfter = df2after["Timestamp"]20energyLevelAfter = df2after["y"]21energyLevelAfter = map(reverse, energyLevelAfter)22happinessLevelAfter = df2after["x"]23minutesAfter = []24for i in range(len(df)):25 date = datetime.datetime.fromtimestamp(df['Timestamp'][i] / 1e3)26 thisMinute = int(date.strftime("%M"))27 thisHour = int(date.strftime("%H"))28 minute = thisHour * 60 + thisMinute29 minutes.append(minute)30for i in range(len(df2after)):31 date = datetime.datetime.fromtimestamp(df['Timestamp'][i] / 1e3)32 thisMinute = int(date.strftime("%M"))33 thisHour = int(date.strftime("%H"))34 minute = thisHour * 60 + thisMinute35 minutesAfter.append(minute)36# AVG morning before37avgMorningBefore = 038avgMorningBeforeEnergy = 039counter = 040counter2 = 041while(counter < len(minutes)):42 if(minutes[counter] < 800):43 avgMorningBefore = avgMorningBefore + minutes[counter]44 avgMorningBeforeEnergy = avgMorningBeforeEnergy + energyLevel[counter]45 counter2 = counter2 + 146 counter = counter + 147avgMorningBefore = avgMorningBefore / counter248avgMorningBeforeEnergy = avgMorningBeforeEnergy / counter249# AVG evening before50avgEveningBefore = 051avgEveningBeforeEnergy = 052counter = 053counter2 = 054while(counter < len(minutes)):55 if(minutes[counter] > 800):56 avgEveningBefore = avgEveningBefore + minutes[counter]57 avgEveningBeforeEnergy = avgEveningBeforeEnergy + energyLevel[counter]58 counter2 = counter2 + 159 counter = counter + 160 print(counter2)61avgEveningBefore = avgEveningBefore / counter262avgEveningBeforeEnergy = avgEveningBeforeEnergy / counter263print(avgMorningBefore, avgMorningBeforeEnergy)64 65# AVG morning after66avgMorningAfter = 067avgMorningAfterEnergy = 068counter = 069counter2 = 070while(counter < len(minutesAfter)):71 if(minutes[counter] < 800):72 avgMorningAfter = avgMorningAfter + minutesAfter[counter]73 avgMorningAfterEnergy = avgMorningAfterEnergy + energyLevelAfter[counter]74 counter2 = counter2 + 175 counter = counter + 176avgMorningAfter = avgMorningAfter / counter277avgMorningAfterEnergy = avgMorningAfterEnergy / counter278# AVG evening after79avgEveningAfter = 080avgEveningAfterEnergy = 081counter = 082counter2 = 083while(counter < len(minutesAfter)):84 if(minutes[counter] > 800):85 avgEveningAfter = avgEveningAfter + minutesAfter[counter]86 avgEveningAfterEnergy = avgEveningAfterEnergy + energyLevelAfter[counter]87 counter2 = counter2 + 188 counter = counter + 189avgEveningAfter = avgEveningAfter / counter290avgEveningAfterEnergy = avgEveningAfterEnergy / counter291box_plot_data=[energyLevel, energyLevelAfter, happinessLevel, happinessLevelAfter]92plt.boxplot(box_plot_data, labels=['Energy before', 'Energy after', 'Happiness before', 'Happiness after'])...
eval_utils.py
Source:eval_utils.py
1import numpy as np2from keras import backend as K3from sklearn.metrics import roc_auc_score456def pairwise_precision_recall_f1(preds, truths):7 tp = 08 fp = 09 fn = 010 n_samples = len(preds)11 for i in range(n_samples - 1):12 pred_i = preds[i]13 for j in range(i + 1, n_samples):14 pred_j = preds[j]15 if pred_i == pred_j:16 if truths[i] == truths[j]:17 tp += 118 else:19 fp += 120 elif truths[i] == truths[j]:21 fn += 122 tp_plus_fp = tp + fp23 tp_plus_fn = tp + fn24 if tp_plus_fp == 0:25 precision = 0.26 else:27 precision = tp / tp_plus_fp28 if tp_plus_fn == 0:29 recall = 0.30 else:31 recall = tp / tp_plus_fn3233 if not precision or not recall:34 f1 = 0.35 else:36 f1 = (2 * precision * recall) / (precision + recall)37 return precision, recall, f1383940def cal_f1(prec, rec):41 return 2*prec*rec/(prec+rec)424344def get_hidden_output(model, inp):45 get_activations = K.function(model.inputs[:1] + [K.learning_phase()], [model.layers[5].get_output_at(0), ])46 activations = get_activations([inp, 0])47 return activations[0]484950def predict(anchor_emb, test_embs):51 score1 = np.linalg.norm(anchor_emb-test_embs[0])52 score2 = np.linalg.norm(anchor_emb-test_embs[1])53 return [score1, score2]545556def full_auc(model, test_triplets):57 """58 Measure AUC for model and ground truth on all items.5960 Returns:61 - float AUC62 """6364 grnds = []65 preds = []66 preds_before = []67 embs_anchor, embs_pos, embs_neg = test_triplets6869 inter_embs_anchor = get_hidden_output(model, embs_anchor)70 inter_embs_pos = get_hidden_output(model, embs_pos)71 inter_embs_neg = get_hidden_output(model, embs_neg)72 # print(inter_embs_pos.shape)7374 accs = []75 accs_before = []7677 for i, e in enumerate(inter_embs_anchor):78 if i % 10000 == 0:79 print('test', i)8081 emb_anchor = e82 emb_pos = inter_embs_pos[i]83 emb_neg = inter_embs_neg[i]84 test_embs = np.array([emb_pos, emb_neg])8586 emb_anchor_before = embs_anchor[i]87 emb_pos_before = embs_pos[i]88 emb_neg_before = embs_neg[i]89 test_embs_before = np.array([emb_pos_before, emb_neg_before])9091 predictions = predict(emb_anchor, test_embs)92 predictions_before = predict(emb_anchor_before, test_embs_before)9394 acc_before = 1 if predictions_before[0] < predictions_before[1] else 095 acc = 1 if predictions[0] < predictions[1] else 096 accs_before.append(acc_before)97 accs.append(acc)9899 grnd = [0, 1]100 grnds += grnd101 preds += predictions102 preds_before += predictions_before103104 auc_before = roc_auc_score(grnds, preds_before)105 auc = roc_auc_score(grnds, preds)106 print('test accuracy before', np.mean(accs_before))107 print('test accuracy after', np.mean(accs))108109 print('test AUC before', auc_before)110 print('test AUC after', auc)
...
Using AI Code Generation
1I am using puppeteer to automate the above test. I am trying to get the test to wait for the storybook-root to load before running the code to use before method of storybook-root. I have tried to use the page.waitForSelector() method, but I am not sure how to use it to wait for the storybook-root to load. I have tried to use the following code:2await page.waitForSelector('.storybook-root');3await page.waitForSelector('.storybook-root', {visible: true});4await page.waitForSelector('.storybook-root', {visible: true, timeout: 0});5await page.waitForSelector('.storybook-root', {visible: true, timeout: 10000});6await page.waitForSelector('.storybook-root', {visible: true, timeout: 10000, polling: 100});7await page.waitForSelector('.storybook-root', {visible: true, timeout: 10000, polling: 100, state: 'attached'});8await page.waitForSelector('.storybook-root', {visible: true
Using AI Code Generation
1import { addDecorator } from "@storybook/react";2import { withInfo } from "@storybook/addon-info";3addDecorator(withInfo);4import { withInfo } from "@storybook/addon-info";5addDecorator(withInfo);6import { withInfo } from "@storybook/addon-info";7import { withKnobs } from "@storybook/addon-knobs";8addDecorator(withInfo);9addDecorator(withKnobs);10import { withInfo } from "@storybook/addon-info";11import { withKnobs } from "@storybook/addon-knobs";12addDecorator(withInfo);13addDecorator(withKnobs);14import { withInfo } from "@storybook/addon-info";15import { withKnobs } from "@storybook/addon-knobs";16addDecorator(withInfo);17addDecorator(withKnobs);
Using AI Code Generation
1import { addDecorator } from '@storybook/react';2import { withA11y } from '@storybook/addon-a11y';3import { withKnobs } from '@storybook/addon-knobs';4addDecorator(withA11y);5addDecorator(withKnobs);6import { addDecorator } from '@storybook/react';7import { withA11y } from '@storybook/addon-a11y';8import { withKnobs } from '@storybook/addon-knobs';9addDecorator(withA11y);10addDecorator(withKnobs);11import { addDecorator } from '@storybook/react';12import { withA11y } from '@storybook/addon-a11y';13import { withKnobs } from '@storybook/addon-knobs';14addDecorator(withA11y);15addDecorator(withKnobs);
Using AI Code Generation
1import { configure } from '@storybook/react';2function loadStories() {3 require('../src/stories');4}5configure(loadStories, module);6import { configure } from '@storybook/react';7const req = require.context('../src/stories', true, /.stories.js$/);8function loadStories() {9 req.keys().forEach(filename => req(filename));10}11configure(loadStories, module);
Using AI Code Generation
1import { configure } from '@storybook/react';2import { setOptions } from '@storybook/addon-options';3import { setDefaults } from '@storybook/addon-info';4import { addDecorator } from '@storybook/react';5import { withInfo } from '@storybook/addon-info';6import { withOptions } from '@storybook/addon-options';7import { addParameters } from '@storybook/react';8import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';9addDecorator(10 withInfo({11 styles: {12 infoBody: {13 },14 source: {15 h1: {16 },17 },18 },19 })20);21addDecorator(22 withOptions({
Using AI Code Generation
1import { configure } from '@storybook/react';2function loadStories() {3 require('../src/stories');4}5configure(loadStories, module);6import { configure } from '@storybook/react';7import '../src/test.js';8function loadStories() {9 require('../src/stories');10}11configure(loadStories, module);12import React from 'react';13import { storiesOf } from '@storybook/react';14import { action } from '@storybook/addon-actions';15import { linkTo } from '@storybook/addon-links';16import { Button, Welcome } from '@storybook/react/demo';17import '../test.js';18storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} />);19storiesOf('Button', module)20 .add('with text', () => (21 <Button onClick={action('clicked')}>Hello Button</Button>22 .add('with some emoji', () => (23 <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>24 ));25import React from 'react';26import ReactDOM from 'react-dom';27import { storiesOf } from '@storybook/react';28import { action } from '@storybook/addon-actions';29import { linkTo } from '@storybook/addon-links';30import { Button, Welcome } from '@storybook/react/demo';31import '../test.js';32import { configure } from '@storybook/react';33storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} />);34storiesOf('Button', module)35 .add('with text', () => (36 <Button onClick={action('clicked')}>Hello Button</Button>37 .add('with some emoji', () => (38 <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>39 ));40import { configure } from '@storybook/react';41import '../src/test.js';42function loadStories() {43 require('../src/stories');44}45configure(loadStories, module);
Using AI Code Generation
1import { configure, addDecorator } from '@storybook/react';2import { withKnobs } from '@storybook/addon-knobs';3import { withThemeProvider } from './storybook-root';4addDecorator(withKnobs);5addDecorator(withThemeProvider);6const req = require.context('../src', true, /\.stories\.js$/);7function loadStories() {8 req.keys().forEach(filename => req(filename));9}10configure(loadStories, module);11import React from 'react';12import { ThemeProvider } from 'styled-components';13import { theme } from '../src/theme';14export const withThemeProvider = storyFn => (15 <ThemeProvider theme={theme}>{storyFn()}</ThemeProvider>16);17export const theme = {18 colors: {19 },20 font: {21 family: {22 },23 size: {24 },25 },26};27import React from 'react';28import { storiesOf } from '@storybook/react';29import Heading from '.';30storiesOf('Heading', module).add('default', () => (31));32import styled from 'styled-components';33 color: ${props => props.theme.colors.black};34 font-family: ${props => props.theme.font.family.primary};35 font-size: ${props => props.theme.font.size.base};36`;37I have a question about the withThemeProvider decorator. It seems like it would be better to import the theme provider from the theme.js file rather than the styled-components package. Is there a reason you did it this way?
Using AI Code Generation
1import { setAddon, addDecorator } from '@storybook/react';2import { withKnobs } from '@storybook/addon-knobs';3addDecorator(withKnobs);4import { configure } from '@storybook/react';5import { setOptions } from '@storybook/addon-options';6import '../test';7import { addParameters } from '@storybook/react';8addParameters({9 options: {10 },11});12import '@storybook/addon-options/register';13import '@storybook/addon-knobs/register';
Using AI Code Generation
1import { configure } from 'storybook-root';2import { storiesOf } from '@storybook/react';3import { withInfo } from '@storybook/addon-info';4configure();5storiesOf('Button', module)6 .addDecorator(withInfo)7 .add('with text', () => (8 ));9import { configure, addDecorator } from 'storybook-root';10import { withInfo } from '@storybook/addon-info';11configure();12addDecorator(withInfo);13storiesOf('Button', module)14 .add('with text', () => (15 ));16import { configure, addDecorator } from 'storybook-root';17import { withInfo } from '@storybook/addon-info';18configure();19addDecorator(withInfo);20storiesOf('Button', module)21 .add('with text', () => (22 ));23import { configure, addParameters } from 'storybook-root';24import { withInfo } from '@storybook/addon-info';25configure();26addParameters({27 info: {28 },29});30storiesOf('Button', module)31 .add('with text', () => (32 ));33import { configure, addDecorator } from 'storybook-root';34import { withInfo } from '@storybook/addon-info';35configure();36addDecorator(withInfo);37storiesOf('Button', module)38 .add('with text', () => (39 ));40import { configure, addDecorator } from 'storybook-root';41import { withInfo } from '@storybook/addon-info';42configure();43addDecorator(withInfo);44storiesOf('Button', module)45 .add('with text', () => (46 ));47import { configure, addParameters } from 'storybook-root';48import { withInfo
Using AI Code Generation
1 (Story) => {2 const { before } = useStorybookRoot();3 before();4 return <Story />;5 },6];7export const useStorybookRoot = () => {8 const before = () => {9 console.log('before method');10 };11 return { before };12};13 (Story) => {14 const { before, after } = useStorybookRoot();15 before();16 return <Story />;17 after();18 },19];20export const useStorybookRoot = () => {21 const before = () => {22 console.log('before method');23 };24 const after = () => {25 console.log('after method');26 };27 return { before, after };28};29 (Story) => {30 const { before, after } = useStorybookRoot();31 before();32 return <Story />;33 after();34 },35];36export const useStorybookRoot = () => {37 const before = () => {38 console.log('before method');39 };40 const after = () => {41 console.log('after method');42 };43 return { before, after };44};45 (Story) => {46 const { before, after } = useStorybookRoot();47 before();48 return <Story />;49 after();50 },51];52export const useStorybookRoot = () => {53 const before = () => {54 console.log('before method');55 };56 const after = () => {57 console.log('after method');58 };59 return { before, after };60};61 (Story) => {62 const { before, after } = useStorybookRoot();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!