How to use d_add method in fMBT

Best Python code snippet using fMBT_python

按人求od.py

Source:按人求od.py Github

copy

Full Screen

1from collections import deque #提高list删除插入速度2import operator3import os4import time5yuefenhuansuan={1:['1',0],2:['2',31],3:['3',59],4:['4',90],5:['5',120],6:['6',151],7:['7',181],8:['8',212],9:['9',243],10:['10',273],11:['11',304],12:['12',334]}6d={}7n=08q_sj=249z_sj=2410yue=411for mm in range(yue,yue+1): 12 for dd in range(q_sj,z_sj+1): 13 riqi=yuefenhuansuan[int(mm)][1]+dd14 if len(str(mm)) <2:15 mm='0'+str(mm)16 if len(str(dd))<2:17 dd='0'+str(dd)18 d={}19 d_add={} #add=address20 d_od={}21 l_inforid=deque(['id,家,晚上乘车点,\n'])22 23 n=024 try:25 with open('E:\广州公交\广州数据及脚本\shuchu//'+str(mm)+'-'+str(dd)+'//chenggong.csv','r+',encoding='UTF-8')as f:26 for hang in f.readlines():27 n+=128 if n%50000==0:29 print(str(mm),str(dd),':',n)30 if n!=1:31 line=hang.split(',')32 if line[0] not in d:33 d[line[0]]={}34 shijian=line[-2].split(' ')35 nianyueri=shijian[0]36 nyr=nianyueri.split('-')37 shifenmiao=shijian[1].split(':')38 shi=shifenmiao[0]39 fen=shifenmiao[1]40 miao=shifenmiao[2]41 sfm=str(shifenmiao[0]+':'+shifenmiao[1]+':'+shifenmiao[2])42 shiju = int(shi) * 3600 + int(fen) * 60 + int(miao) - 86400 * (riqi - yuefenhuansuan[int(nyr[1])][1]-int(nyr[2])) #将时间换成以某一天零点为基准,为以后做排序准备43 d[line[0]][shiju]=hang44 except:45 with open('E:\广州公交\广州数据及脚本\shuchu//'+str(int(mm)+1)+'-'+str(1)+'//chenggong.csv','r+',encoding='UTF-8')as f:46 for hang in f.readlines():47 n+=148 if n%50000==0:49 print(str(mm),str(dd),':',n)50 if n!=1:51 line=hang.split(',')52 if line[0] not in d:53 d[line[0]]={}54 shijian=line[-2].split(' ')55 nianyueri=shijian[0]56 nyr=nianyueri.split('-')57 shifenmiao=shijian[1].split(':')58 shi=shifenmiao[0]59 fen=shifenmiao[1]60 miao=shifenmiao[2]61 sfm=str(shifenmiao[0]+':'+shifenmiao[1]+':'+shifenmiao[2])62 shiju = int(shi) * 3600 + int(fen) * 60 + int(miao) - 86400 * (riqi - yuefenhuansuan[int(nyr[1])][1]-int(nyr[2])) #将时间换成以某一天零点为基准,为以后做排序准备63 d[line[0]][shiju]=hang64 65 l=[]66 67 for k,v in d.items():68 sorted_kk=sorted(v.items(),key=operator.itemgetter(0))69 for x in sorted_kk:70 l.append(x[1])71 72 73 d={'':{'day':{'qidian':{},'zhongdian':{}},'night':{'qidian':{},'zhongdian':{}}}}74 75 y=0 #是否进行判断早高峰起点依据,0为判断,1为不判断76 yy=0 #是否进行判断晚高峰起点依据,0为判断,1为不判断77 z=1 #是否录入早高峰终点依据,0为录入,1为不录入78 zz=1 #是否录入晚高峰终点依据,0为录入,1为不录入79 day_zd='null' #白天终点80 night_zd='null' #晚上终点81 lastID='' #记录上一id,为写入zhongdian作准备82 for line in l:83 line=line.split(',')84 shijian=line[-2].split(' ')85 date=nianyueri.split('-')86 shijian=shijian[1].split(':')87 fzj=int(shijian[0])*60+int(shijian[1]) #fenzhongju,以分钟为单位距0点88 riqi=yuefenhuansuan[int(date[1])][1]+int(date[2])89 zhandian=line[-3]90 91 if line[0] != lastID:92 rizi=riqi93 y=0 #是否进行判断早高峰起点依据94 yy=0 #是否进行判断晚高峰起点依据95 #创建起点和终点的字典,并各自有上班与下班时段字典96 if line[0] not in d:97 d[line[0]]={'day':{'qidian':{},'zhongdian':{}},'night':{'qidian':{},'zhongdian':{}}} 98 #将上一ID的早晚时间段的终点录入99 if z==0:100 z=1101 if day_zd in d[lastID]['day']['zhongdian']:102 d[lastID]['day']['zhongdian'][day_zd]+=1103 else:104 d[lastID]['day']['zhongdian'][day_zd]=1 105 if zz==0:106 z=1107 if night_zd in d[lastID]['night']['zhongdian']:108 d[lastID]['night']['zhongdian'][night_zd]+=1109 else:110 d[lastID]['night']['zhongdian'][night_zd]=1111 lastID=line[0]112 113 #判断早高峰起点,并记录有可能的终点114 if fzj >=420 and fzj <=540 : #因为限制了时间,有可能开始的起点不在这里,如果只是想知道其家庭工作地点可放宽时间段,但不能掌握其是否在高峰时段出行115 if y==0 :116 y=1117 if zhandian in d[line[0]]['day']['qidian']:118 d[line[0]]['day']['qidian'][zhandian]+=1119 else :120 d[line[0]]['day']['qidian'][zhandian]=1121 122 #判断晚高峰起点,并记录有可能的终点123 elif fzj >=1050 and fzj <=1170: 124 if yy==0 :125 #yy=1126 if zhandian in d[line[0]]['night']['qidian']:127 d[line[0]]['night']['qidian'][zhandian]+=1128 else :129 d[line[0]]['night']['qidian'][zhandian]=1130 131 if line[0] == lastID: 132 if riqi==rizi:133 #判断早高峰起点,并记录有可能的终点134 if fzj >=420 and fzj <=540 : 135 if y==0 :136 y=1137 if zhandian in d[line[0]]['day']['qidian']:138 d[line[0]]['day']['qidian'][zhandian]+=1139 else :140 d[line[0]]['day']['qidian'][zhandian]=1141 142 #判断晚高峰起点,并记录有可能的终点143 elif fzj >=1050 and fzj <=1170: 144 if yy==0 :145 #yy=1146 if zhandian in d[line[0]]['night']['qidian']:147 d[line[0]]['night']['qidian'][zhandian]+=1148 else :149 d[line[0]]['night']['qidian'][zhandian]=1150 151 152 if riqi>rizi:153 rizi=riqi154 #将上一天的早晚时间段的终点录入155 if z==0:156 z=1157 if day_zd in d[lastID]['day']['zhongdian']:158 d[lastID]['day']['zhongdian'][day_zd]+=1159 else:160 d[lastID]['day']['zhongdian'][day_zd]=1161 if zz==0:162 zz=1163 if night_zd in d[lastID]['night']['zhongdian']:164 d[lastID]['night']['zhongdian'][night_zd]+=1165 else:166 d[lastID]['night']['zhongdian'][night_zd]=1167 168 #判断早高峰起点,并记录有可能的终点169 if fzj >=420 and fzj <=540 : 170 if y==0 :171 y=1172 if zhandian in d[line[0]]['day']['qidian']:173 d[line[0]]['day']['qidian'][zhandian]+=1174 else :175 d[line[0]]['day']['qidian'][zhandian]=1176 177 #判断晚高峰起点,并记录有可能的终点178 elif fzj >=1050 and fzj <=1170: 179 if yy==0 :180 #yy=1181 if zhandian in d[line[0]]['night']['qidian']:182 d[line[0]]['night']['qidian'][zhandian]+=1183 else :184 d[line[0]]['night']['qidian'][zhandian]=1185 186 d.pop('') 187 188 #判断家,工作地点189 d_add={} #add=address190 li=['day_qd_max','day_zd_max','night_qd_max','night_zd_max']191 l_ri=['day','night']192 l_qz=['qidian','zhongdian']193 for k,v in d.items():194 d_add[k]={}195 for x in li:196 locals()[x]=''197 nn=0198 #给li里的变量赋值,分别表示早晚起终点的最大值的站点199 for t in l_ri:200 for tt in l_qz:201 if v[t][tt]:202 locals()[li[nn]]=sorted(v[t][tt],key=lambda x:v[t][tt][x])[-1]203 else:204 locals()[li[nn]]='null'205 nn+=1206 """#如果家庭工作地点都是地铁站207 if day_qd_max == night_zd_max:208 d_add[k]['jia']= day_qd_max209 if day_zd_max==night_qd_max:210 d_add[k]['gongsi']= day_zd_max"""211 212 #如果不是家或公司旁没有地铁站或BRT站,简单的认为白天起点最多的是家,晚上起点最多的是工作地点213 if 'jia' not in d_add[k]:214 d_add[k]['jia']= day_qd_max215 if 'gongsi' not in d_add[k]:216 d_add[k]['gongsi']= night_qd_max217 """#也可以按比例最大的估算家或地点,以下是示例218 if 'jia' not in d_add[k]:219 dq_he=0220 d_add[k]['jia']=[]221 for x in v['day']['qidian'].values():222 dq_he+=x223 for kk,vv in v['day']['qidian'].items():224 if vv/dq_he>0.25:225 d_add[k]['jia'].append(kk) """226 if d_add[k]['jia']!='null' and d_add[k]['gongsi']!='null':227 strr=k+','+d_add[k]['jia']+','228 for key,value in v['night']['qidian'].items():229 strr+=(key+',')230 231 strr+='\n'232 l_inforid.append(strr)233 234 d_od={}235 l_jg=['jia','gongsi']236 l_zd=['null']237 for k,v in d_add.items():238 od=(v['jia'],v['gongsi'])239 if od not in d_od:240 d_od[od]=0241 for x in od:242 if x not in l_zd:243 l_zd.append(x)244 d_od[od]+=1245 l_shuchu=[' ,']246 for x in l_zd:247 l_shuchu.append(x)248 l_shuchu.append(',')249 l_shuchu.append('\n')250 rzs=0 #人总数251 zdwbd=0 #早搭晚不搭252 wdzbd=0 #晚搭早不搭253 for x in l_zd:254 l_shuchu.append(x)255 l_shuchu.append(',')256 if x !='null':257 if (x,'null') in d_od:258 zdwbd+=d_od[(x,'null')] #统计早搭晚不搭259 if ('null',x) in d_od:260 wdzbd+=d_od[('null',x)] #统计晚搭早不搭261 for xx in l_zd:262 if (x,xx) in d_od:263 l_shuchu.append(d_od[(x,xx)])264 rzs+=d_od[(x,xx)]265 l_shuchu.append(',')266 else:267 l_shuchu.append('0')268 l_shuchu.append(',')269 270 l_shuchu.append('\n')271 272 273 274 if os.path.exists('E:\广州公交\yjt\人_od\\'+str(mm)+str(dd)) == False:275 os.mkdir('E:\广州公交\yjt\人_od\\'+str(mm)+str(dd)+'/')276 277 with open(r'E:\广州公交\yjt\人_od\\'+str(mm)+str(dd)+'\\shuchu'+str(mm)+str(dd)+'.csv','w+',encoding='utf-8')as f:278 for x in l_shuchu:279 f.write(str(x))280 281 282 with open(r'E:\广州公交\yjt\人_od\\'+str(mm)+str(dd)+'\\id_information.csv','w+',encoding='utf-8')as f:283 for x in l_inforid:284 f.write(str(x))285 286 gg=0287 l_xinxi=['人数:',rzs,'\n高峰内公交换乘的人数:']288 with open(r'E:\广州公交\yjt\人_od\\'+str(mm)+str(dd)+'\\id_information.csv','r+',encoding='utf-8')as f:289 for line in f.readlines():290 line=line.split(',')291 if len(line)>4:292 gg+=1293 l_xinxi.append(gg)294 295 with open(r'E:\广州公交\yjt\人_od\\'+str(mm)+str(dd)+'\\xinxi.txt','w+',encoding='utf-8')as f:296 for x in l_xinxi:297 f.write(str(x))298 f.write('\n非高峰搭车人数:')299 f.write(str(d_od[('null','null')]))300 f.write('\n早搭晚不搭:')301 f.write(str(zdwbd))302 f.write('\n晚搭早不搭:')303 f.write(str(wdzbd))304 ...

Full Screen

Full Screen

fuel_injection_perfection.py

Source:fuel_injection_perfection.py Github

copy

Full Screen

1#operations: 1. add 1, 2. remove 1, 3. divide with 2 (even)23def solution(n):4 d={"1":0,"2":1}5 while True:6 dict_update={}7 for num in d:8 if(num==n):9 return d[num]10 m=int(num)11 if(str(m+1) not in d.keys()):12 dict_update.update({str(m+1):d[num]+1})13 if(m-1>1 and str(m-1) not in d.keys()):14 dict_update.update({str(m-1):d[num]+1})15 if(str(2*m) not in d.keys()):16 dict_update.update({str(2*m):d[num]+1})17 d.update(dict_update)18 #print(d)1920def solution2(n):21 d1={"1":0,"2":1} #dict with all minimum costs22 d2={"2":1} #temporary dict only for nth step with numbers of cost n23 cost=124 while True:25 d_add={}26 cost+=127 for num in d2: #explore only in d228 m=int(num)29 for num2 in [str(m+1),str(m-1),str(2*m)]:30 if num2 not in d1.keys():31 d_add.update({num2:cost})32 33 if(n in d_add):34 return d_add[n]3536 d1.update(d_add)37 d2=d_add3839 #print(d1)40 #print(d2)4142def solution3(n):43 # Mark all the vertices as not visited44 visited = {"1":0,"2":1}4546 # Create a queue for BFS47 queue = ["2"]4849 # Mark the source node as 50 # visited and enqueue it5152 while True:5354 # Dequeue a vertex from 55 # queue and print it56 #print(queue)57 s = queue.pop(0)58 #print (s, end = " ")5960 # Get all adjacent vertices of the61 # dequeued vertex s. If a adjacent62 # has not been visited, then mark it63 # visited and enqueue it64 num=int(s)65 cost=visited[s]66 for i in [str(num-1),str(num+1),str(2*num)]:67 if i not in visited:68 if(i==n): return cost+169 queue.append(i)70 visited[i] = cost+17172def solution4(n):73 t=n74 b=bin(int(n))75 steps=076 while True:77 steps+=178 if(b[-1]=='0'):79 t=int(b,2)//280 elif(b==bin(3) or b[-2:]=='01'):81 t=int(b,2)-182 else:83 t=int(b,2)+184 #print(t)85 b=bin(t)86 if(t==1):87 return steps888990def solution5(n):91 temp=int(n)92 steps=093 while True:94 a=temp%495 steps+=196 if(a==0 or a==2):97 temp=temp//298 elif(temp==3 or a==1):99 temp-=1100 else:101 temp+=1102 #print(t)103 if(temp==1):104 return steps105 ...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful