Best Python code snippet using locust
behave_api.py
Source:behave_api.py
1# -*- coding: utf-8 -*-2import datetime3from django.conf import settings4from gna.tabulate.models import (5 PaymentLevel,6 ZelInc,7 ZelDec,8 DiaInc,9 DiaDec,10 KarmaInc,11 KarmaDec,12 NewUserLevel,13 ArenaChallenge,14 DungeonKey,15 UnitEvo,16 UnitMix,17 UnitSell,18 FacilityLvup,19 LocationLvup,20 BmRefresh,21 BmBuy,22 BmGoods,23 BrvItemMst,24 BrvUnitMst,25)26from gna.common import (27 div_operation,28)29##### str #####30def _get_date_str(date):31 if type(date)==datetime.date or type(date)==datetime.datetime:32 return date.strftime('%Y-%m-%d')33 return date34def _get_date_by_str(date_str):35 return datetime.datetime.strptime(date_str, '%Y-%m-%d')36def _get_str_by_int(value):37 if value:38 return str(int(value))39 else:40 return None41def _get_str_by_float(value):42 if value:43 return '%.1f' % (value)44 else:45 return None46def _get_percent_by_float(value):47 if value:48 return '%.1f%%' % (value*100.0)49 else:50 return None51##### api #####52# å½æ¥åè§ç级åå¸53class NewUserLevelObject(object):54 percent = None55 total_percent = None56 def __init__(self, date, zone, lv, count):57 self.date = date58 self.zone = zone59 self.lv = lv60 self.count = count61 def get_str(self):62 self.date_str = _get_date_str(self.date)63 self.zone_str = settings.TABULATE_ZONE_NAME[self.zone]64 self.lv_str = _get_str_by_int(self.lv)65 self.count_str = _get_str_by_int(self.count)66 self.percent_str = _get_percent_by_float(self.percent)67 self.total_percent_str = _get_percent_by_float(self.total_percent)68def get_new_user_level_objs_list(db, date, zone):69 query_data = NewUserLevel.objects.using(db).filter(date=date, zone=zone)70 objs = []71 all_count = 072 for data in query_data:73 lv, count = data.lv, data.count74 obj = NewUserLevelObject(date, zone, lv, count)75 all_count += count76 objs.append(obj)77 objs.sort(key=lambda x: x.lv)78 total = 079 for obj in objs:80 obj.percent = div_operation(obj.count, all_count)81 total += obj.count82 obj.total_percent = div_operation(total, all_count)83 obj.get_str()84 return objs85def get_new_user_level_summary_objs_list(db, date):86 query_data = NewUserLevel.objects.using(db).filter(date=date)87 objs = []88 obj_dict = {}89 all_count = 090 for data in query_data:91 lv, count = data.lv, data.count92 if lv in obj_dict:93 obj_dict[lv].count += count94 else:95 obj = NewUserLevelObject(date, 'summary', lv, count)96 objs.append(obj)97 obj_dict[lv] = obj98 all_count += count99 objs.sort(key=lambda x: x.lv)100 total = 0101 for obj in objs:102 obj.percent = div_operation(obj.count, all_count)103 total += obj.count104 obj.total_percent = div_operation(total, all_count)105 obj.get_str()106 return objs107# å
å¼æ¡£æ¬¡108class PaymentLevelObject(object):109 def __init__(self, date, platform, zone, purchase_id, user_count, times_count, amount):110 self.date = date111 self.zone = zone112 self.platform = platform113 self.purchase_id = purchase_id114 self.user_count = user_count115 self.times_count = times_count116 self.amount = amount 117 def get_str(self):118 self.date_str = _get_date_str(self.date)119 self.zone_str = settings.TABULATE_ZONE_NAME[self.zone]120 self.platform_str = _get_str_by_int(self.platform)121 self.purchase_id_str = settings.TABULATE_PURCHASE_ID_NAME[self.purchase_id]122 self.user_count_str = _get_str_by_int(self.user_count)123 self.times_count_str = _get_str_by_int(self.times_count)124 self.amount_str = _get_str_by_int(self.amount)125def get_payment_level_objs_list(db, date, zone):126 query_data = PaymentLevel.objects.using(db).filter(date=date, zone=zone)127 objs = []128 for data in query_data:129 platform, purchase_id, user_count, times_count, amount = data.platform, data.purchase_id, data.user_count, data.times_count, data.amount130 obj = PaymentLevelObject(date, platform, zone, purchase_id, user_count, times_count, amount)131 obj.get_str()132 objs.append(obj)133 objs.sort(key=lambda x: x.purchase_id)134 return objs135def get_payment_level_summary_objs_list(db, date):136 zone = 'summary'137 query_data = PaymentLevel.objects.using(db).filter(date=date)138 objs = []139 obj_dict = {}140 for data in query_data:141 platform, purchase_id, user_count, times_count, amount = data.platform, data.purchase_id, data.user_count, data.times_count, data.amount142 if purchase_id in obj_dict:143 obj = obj_dict[purchase_id]144 obj.user_count += user_count145 obj.times_count += times_count146 obj.amount += amount147 else:148 obj = PaymentLevelObject(date, platform, zone, purchase_id, user_count, times_count, amount)149 objs.append(obj)150 obj_dict[purchase_id] = obj151 objs.sort(key=lambda x: x.purchase_id) 152 for obj in objs:153 obj.get_str()154 return objs155# éå¸äº§åº156class ResourceObject(object):157 def __init__(self, date, platform, zone, channel_id, user_count, times_count, amount):158 self.date = date159 self.zone = zone160 self.platform = platform161 self.channel_id = channel_id162 self.user_count = user_count163 self.times_count = times_count164 self.amount = amount 165 def get_str(self):166 self.date_str = _get_date_str(self.date)167 self.zone_str = settings.TABULATE_ZONE_NAME[self.zone]168 self.platform_str = _get_str_by_int(self.platform)169 if self.channel_id in settings.TABULATE_RESOURCE_CHANNEL_ID_NAME:170 self.channel_id_str = settings.TABULATE_RESOURCE_CHANNEL_ID_NAME[self.channel_id]171 else:172 self.channel_id_str = str(self.channel_id)173 self.user_count_str = _get_str_by_int(self.user_count)174 self.times_count_str = _get_str_by_int(self.times_count)175 self.amount_str = _get_str_by_int(self.amount)176def get_zel_inc_objs_list(db, date, zone):177 query_data = ZelInc.objects.using(db).filter(date=date, zone=zone)178 objs = []179 for data in query_data:180 platform, channel_id, user_count, times_count, amount = data.platform, data.channel_id, data.user_count, data.times_count, data.amount181 obj = ResourceObject(date, platform, zone, channel_id, user_count, times_count, amount)182 obj.get_str()183 objs.append(obj)184 objs.sort(key=lambda x: x.channel_id)185 return objs186def get_zel_inc_summary_objs_list(db, date):187 zone = 'summary'188 query_data = ZelInc.objects.using(db).filter(date=date)189 objs = []190 obj_dict = {}191 for data in query_data:192 platform, channel_id, user_count, times_count, amount = data.platform, data.channel_id, data.user_count, data.times_count, data.amount193 if channel_id in obj_dict:194 obj = obj_dict[channel_id]195 obj.user_count += user_count196 obj.times_count += times_count197 obj.amount += amount198 else:199 obj = ResourceObject(date, platform, zone, channel_id, user_count, times_count, amount)200 objs.append(obj)201 obj_dict[channel_id] = obj202 objs.sort(key=lambda x: x.channel_id)203 for obj in objs:204 obj.get_str()205 return objs206# éå¸æ¶è207def get_zel_dec_objs_list(db, date, zone):208 query_data = ZelDec.objects.using(db).filter(date=date, zone=zone)209 objs = []210 for data in query_data:211 platform, channel_id, user_count, times_count, amount = data.platform, data.channel_id, data.user_count, data.times_count, data.amount212 obj = ResourceObject(date, platform, zone, channel_id, user_count, times_count, amount)213 obj.get_str()214 objs.append(obj)215 objs.sort(key=lambda x: x.channel_id)216 return objs217def get_zel_dec_summary_objs_list(db, date):218 zone = 'summary'219 query_data = ZelDec.objects.using(db).filter(date=date)220 objs = []221 obj_dict = {}222 for data in query_data:223 platform, channel_id, user_count, times_count, amount = data.platform, data.channel_id, data.user_count, data.times_count, data.amount224 if channel_id in obj_dict:225 obj = obj_dict[channel_id]226 obj.user_count += user_count227 obj.times_count += times_count228 obj.amount += amount229 else:230 obj = ResourceObject(date, platform, zone, channel_id, user_count, times_count, amount)231 objs.append(obj)232 obj_dict[channel_id] = obj233 objs.sort(key=lambda x: x.channel_id)234 for obj in objs:235 obj.get_str()236 return objs237# é»ç³äº§åº238def get_dia_inc_objs_list(db, date, zone):239 query_data = DiaInc.objects.using(db).filter(date=date, zone=zone)240 objs = []241 for data in query_data:242 platform, channel_id, user_count, times_count, amount = data.platform, data.channel_id, data.user_count, data.times_count, data.amount243 obj = ResourceObject(date, platform, zone, channel_id, user_count, times_count, amount)244 obj.get_str()245 objs.append(obj)246 objs.sort(key=lambda x: x.channel_id)247 return objs248def get_dia_inc_summary_objs_list(db, date):249 zone = 'summary'250 query_data = DiaInc.objects.using(db).filter(date=date)251 objs = []252 obj_dict = {}253 for data in query_data:254 platform, channel_id, user_count, times_count, amount = data.platform, data.channel_id, data.user_count, data.times_count, data.amount255 if channel_id in obj_dict:256 obj = obj_dict[channel_id]257 obj.user_count += user_count258 obj.times_count += times_count259 obj.amount += amount260 else:261 obj = ResourceObject(date, platform, zone, channel_id, user_count, times_count, amount)262 objs.append(obj)263 obj_dict[channel_id] = obj264 objs.sort(key=lambda x: x.channel_id)265 for obj in objs:266 obj.get_str()267 return objs268# é»ç³æ¶è269def get_dia_dec_objs_list(db, date, zone):270 query_data = DiaDec.objects.using(db).filter(date=date, zone=zone)271 objs = []272 for data in query_data:273 platform, channel_id, user_count, times_count, amount = data.platform, data.channel_id, data.user_count, data.times_count, data.amount274 obj = ResourceObject(date, platform, zone, channel_id, user_count, times_count, amount)275 obj.get_str()276 objs.append(obj)277 objs.sort(key=lambda x: x.channel_id)278 return objs279def get_dia_dec_summary_objs_list(db, date):280 zone = 'summary'281 query_data = DiaDec.objects.using(db).filter(date=date)282 objs = []283 obj_dict = {}284 for data in query_data:285 platform, channel_id, user_count, times_count, amount = data.platform, data.channel_id, data.user_count, data.times_count, data.amount286 if channel_id in obj_dict:287 obj = obj_dict[channel_id]288 obj.user_count += user_count289 obj.times_count += times_count290 obj.amount += amount291 else:292 obj = ResourceObject(date, platform, zone, channel_id, user_count, times_count, amount)293 objs.append(obj)294 obj_dict[channel_id] = obj295 objs.sort(key=lambda x: x.channel_id)296 for obj in objs:297 obj.get_str()298 return objs299# é产åº300def get_karma_inc_objs_list(db, date, zone):301 query_data = KarmaInc.objects.using(db).filter(date=date, zone=zone)302 objs = []303 for data in query_data:304 platform, channel_id, user_count, times_count, amount = data.platform, data.channel_id, data.user_count, data.times_count, data.amount305 obj = ResourceObject(date, platform, zone, channel_id, user_count, times_count, amount)306 obj.get_str()307 objs.append(obj)308 objs.sort(key=lambda x: x.channel_id)309 return objs310def get_karma_inc_summary_objs_list(db, date):311 zone = 'summary'312 query_data = KarmaInc.objects.using(db).filter(date=date)313 objs = []314 obj_dict = {}315 for data in query_data:316 platform, channel_id, user_count, times_count, amount = data.platform, data.channel_id, data.user_count, data.times_count, data.amount317 if channel_id in obj_dict:318 obj = obj_dict[channel_id]319 obj.user_count += user_count320 obj.times_count += times_count321 obj.amount += amount322 else:323 obj = ResourceObject(date, platform, zone, channel_id, user_count, times_count, amount)324 objs.append(obj)325 obj_dict[channel_id] = obj326 objs.sort(key=lambda x: x.channel_id)327 for obj in objs:328 obj.get_str()329 return objs330# éæ¶è331def get_karma_dec_objs_list(db, date, zone):332 query_data = KarmaDec.objects.using(db).filter(date=date, zone=zone)333 objs = []334 for data in query_data:335 platform, channel_id, user_count, times_count, amount = data.platform, data.channel_id, data.user_count, data.times_count, data.amount336 obj = ResourceObject(date, platform, zone, channel_id, user_count, times_count, amount)337 obj.get_str()338 objs.append(obj)339 objs.sort(key=lambda x: x.channel_id)340 return objs341def get_karma_dec_summary_objs_list(db, date):342 zone = 'summary'343 query_data = KarmaDec.objects.using(db).filter(date=date)344 objs = []345 obj_dict = {}346 for data in query_data:347 platform, channel_id, user_count, times_count, amount = data.platform, data.channel_id, data.user_count, data.times_count, data.amount348 if channel_id in obj_dict:349 obj = obj_dict[channel_id]350 obj.user_count += user_count351 obj.times_count += times_count352 obj.amount += amount353 else:354 obj = ResourceObject(date, platform, zone, channel_id, user_count, times_count, amount)355 objs.append(obj)356 obj_dict[channel_id] = obj357 objs.sort(key=lambda x: x.channel_id)358 for obj in objs:359 obj.get_str()360 return objs361# å¡çè¿å362class CardObject(object):363 def __init__(self, date, zone, user_count, times_count):364 self.date = date365 self.zone = zone366 self.user_count = user_count367 self.times_count = times_count368 def get_str(self):369 self.date_str = _get_date_str(self.date)370 self.zone_str = settings.TABULATE_ZONE_NAME[self.zone]371 self.user_count_str = _get_str_by_int(self.user_count)372 self.times_count_str = _get_str_by_int(self.times_count)373def get_unit_evo_objs_list(db, date, zone):374 query_data = UnitEvo.objects.using(db).filter(date=date, zone=zone)375 objs = []376 for data in query_data:377 user_count, times_count = data.user_count, data.times_count378 obj = CardObject(date, zone, user_count, times_count)379 obj.get_str()380 objs.append(obj)381 return objs382def get_unit_evo_summary_objs_list(db, date):383 zone = 'summary'384 query_data = UnitEvo.objects.using(db).filter(date=date)385 objs = [CardObject(date, zone, 0, 0), ]386 for data in query_data:387 user_count, times_count = data.user_count, data.times_count388 obj = objs[0]389 obj.user_count += user_count390 obj.times_count += times_count391 for obj in objs:392 obj.get_str()393 return objs394# å¡ç强å395def get_unit_mix_objs_list(db, date, zone):396 query_data = UnitMix.objects.using(db).filter(date=date, zone=zone)397 objs = []398 for data in query_data:399 user_count, times_count = data.user_count, data.times_count400 obj = CardObject(date, zone, user_count, times_count)401 obj.get_str()402 objs.append(obj)403 return objs404def get_unit_mix_summary_objs_list(db, date):405 zone = 'summary'406 query_data = UnitMix.objects.using(db).filter(date=date)407 objs = [CardObject(date, zone, 0, 0), ]408 for data in query_data:409 user_count, times_count = data.user_count, data.times_count410 obj = objs[0]411 obj.user_count += user_count412 obj.times_count += times_count413 for obj in objs:414 obj.get_str()415 return objs416# å¡çåºå®417def get_unit_sell_objs_list(db, date, zone):418 query_data = UnitSell.objects.using(db).filter(date=date, zone=zone)419 objs = []420 for data in query_data:421 user_count, times_count = data.user_count, data.times_count422 obj = CardObject(date, zone, user_count, times_count)423 obj.get_str()424 objs.append(obj)425 return objs426def get_unit_sell_summary_objs_list(db, date):427 zone = 'summary'428 query_data = UnitSell.objects.using(db).filter(date=date)429 objs = [CardObject(date, zone, 0, 0), ]430 for data in query_data:431 user_count, times_count = data.user_count, data.times_count432 obj = objs[0]433 obj.user_count += user_count434 obj.times_count += times_count435 for obj in objs:436 obj.get_str()437 return objs438# 建çå级439class FacilityLvupObject(object):440 def __init__(self, date, zone, facility_id, user_count, times_count):441 self.date = date442 self.zone = zone443 self.facility_id = facility_id444 self.user_count = user_count445 self.times_count = times_count446 def get_str(self):447 self.date_str = _get_date_str(self.date)448 self.zone_str = settings.TABULATE_ZONE_NAME[self.zone]449 self.facility_id_str = settings.TABULATE_FACILITY_ID_NAME[self.facility_id]450 self.user_count_str = _get_str_by_int(self.user_count)451 self.times_count_str = _get_str_by_int(self.times_count)452def get_facility_lvup_objs_list(db, date, zone):453 query_data = FacilityLvup.objects.using(db).filter(date=date, zone=zone)454 objs = []455 for data in query_data:456 facility_id, user_count, times_count = data.facility_id, data.user_count, data.times_count457 obj = FacilityLvupObject(date, zone, facility_id, user_count, times_count)458 obj.get_str()459 objs.append(obj)460 objs.sort(key=lambda x: x.facility_id)461 return objs462def get_facility_lvup_summary_objs_list(db, date):463 zone = 'summary'464 query_data = FacilityLvup.objects.using(db).filter(date=date)465 objs = []466 obj_dict = {}467 for data in query_data:468 facility_id, user_count, times_count = data.facility_id, data.user_count, data.times_count469 if facility_id in obj_dict:470 obj = obj_dict[facility_id]471 obj.user_count += user_count472 obj.times_count += times_count473 else:474 obj = FacilityLvupObject(date, zone, facility_id, user_count, times_count)475 objs.append(obj)476 obj_dict[facility_id] = obj477 objs.sort(key=lambda x: x.facility_id)478 for obj in objs:479 obj.get_str()480 return objs481# èµæºå级482class LocationLvupObject(object):483 def __init__(self, date, zone, location_id, user_count, times_count):484 self.date = date485 self.zone = zone486 self.location_id = location_id487 self.user_count = user_count488 self.times_count = times_count489 def get_str(self):490 self.date_str = _get_date_str(self.date)491 self.zone_str = settings.TABULATE_ZONE_NAME[self.zone]492 self.location_id_str = settings.TABULATE_LOCATION_ID_NAME[self.location_id]493 self.user_count_str = _get_str_by_int(self.user_count)494 self.times_count_str = _get_str_by_int(self.times_count)495def get_location_lvup_objs_list(db, date, zone):496 query_data = LocationLvup.objects.using(db).filter(date=date, zone=zone)497 objs = []498 for data in query_data:499 location_id, user_count, times_count = data.location_id, data.user_count, data.times_count500 obj = LocationLvupObject(date, zone, location_id, user_count, times_count)501 obj.get_str()502 objs.append(obj)503 objs.sort(key=lambda x: x.location_id)504 return objs505def get_location_lvup_summary_objs_list(db, date):506 zone = 'summary'507 query_data = LocationLvup.objects.using(db).filter(date=date)508 objs = []509 obj_dict = {}510 for data in query_data:511 location_id, user_count, times_count = data.location_id, data.user_count, data.times_count512 if location_id in obj_dict:513 obj = obj_dict[location_id]514 obj.user_count += user_count515 obj.times_count += times_count516 else:517 obj = LocationLvupObject(date, zone, location_id, user_count, times_count)518 objs.append(obj)519 obj_dict[location_id] = obj520 objs.sort(key=lambda x: x.location_id)521 for obj in objs:522 obj.get_str()523 return objs524# ç«æåºææ525class ArenaChallengeObject(object):526 def __init__(self, date, zone, result, user_count, times_count, point_count, karma_count):527 self.date = date528 self.zone = zone529 self.result = result530 self.user_count = user_count531 self.times_count = times_count532 self.point_count = point_count533 self.karma_count = karma_count534 def get_str(self):535 self.date_str = _get_date_str(self.date)536 self.zone_str = settings.TABULATE_ZONE_NAME[self.zone]537 self.result_str = settings.TABULATE_ARENA_CHALLENGE_RESULT_NAME[self.result]538 self.user_count_str = _get_str_by_int(self.user_count)539 self.times_count_str = _get_str_by_int(self.times_count)540 self.point_count_str = _get_str_by_int(self.point_count)541 self.karma_count_str = _get_str_by_int(self.karma_count)542def get_arena_challenge_objs_list(db, date, zone):543 query_data = ArenaChallenge.objects.using(db).filter(date=date, zone=zone)544 objs = []545 for data in query_data:546 result, user_count, times_count, point_count, karma_count = data.result, data.user_count, data.times_count, data.point_count, data.karma_count547 obj = ArenaChallengeObject(date, zone, result, user_count, times_count, point_count, karma_count)548 obj.get_str()549 objs.append(obj)550 objs.sort(key=lambda x: x.result)551 return objs552def get_arena_challenge_summary_objs_list(db, date):553 zone = 'summary'554 query_data = ArenaChallenge.objects.using(db).filter(date=date)555 objs = []556 obj_dict = {}557 for data in query_data:558 result, user_count, times_count, point_count, karma_count = data.result, data.user_count, data.times_count, data.point_count, data.karma_count559 if result in obj_dict:560 obj = obj_dict[result]561 obj.user_count += user_count562 obj.times_count += times_count563 obj.point_count += point_count564 obj.karma_count += karma_count565 else:566 obj = ArenaChallengeObject(date, zone, result, user_count, times_count, point_count, karma_count)567 objs.append(obj)568 obj_dict[result] = obj569 objs.sort(key=lambda x: x.result)570 for obj in objs:571 obj.get_str()572 return objs573# å¸é½å
°å¾·å°-é¶é¥å574class DungeonKeyObject(object):575 def __init__(self, date, zone, do_type, user_count, times_count, key_count):576 self.date = date577 self.zone = zone578 self.do_type = do_type579 self.user_count = user_count580 self.times_count = times_count581 self.key_count = key_count582 def get_str(self):583 self.date_str = _get_date_str(self.date)584 self.zone_str = settings.TABULATE_ZONE_NAME[self.zone]585 self.do_type_str = settings.TABULATE_DUNGEON_KEY_DO_TYPE_NAME[self.do_type]586 self.user_count_str = _get_str_by_int(self.user_count)587 self.times_count_str = _get_str_by_int(self.times_count)588 self.key_count_str = _get_str_by_int(self.key_count)589def get_dungeon_sliver_key_objs_list(db, date, zone):590 query_data = DungeonKey.objects.using(db).filter(date=date, zone=zone, key_id=settings.TABULATE_DUNGEON_SLIVER_KEY_CODE)591 objs = []592 for data in query_data:593 do_type, user_count, times_count, key_count = data.do_type, data.user_count, data.times_count, data.key_count594 obj = DungeonKeyObject(date, zone, do_type, user_count, times_count, key_count)595 obj.get_str()596 objs.append(obj)597 objs.sort(key=lambda x: x.do_type)598 return objs599def get_dungeon_sliver_key_summary_objs_list(db, date):600 zone = 'summary'601 query_data = DungeonKey.objects.using(db).filter(date=date, key_id=settings.TABULATE_DUNGEON_SLIVER_KEY_CODE)602 objs = []603 obj_dict = {}604 for data in query_data:605 do_type, user_count, times_count, key_count = data.do_type, data.user_count, data.times_count, data.key_count606 if do_type in obj_dict:607 obj = obj_dict[do_type]608 obj.user_count += user_count609 obj.times_count += times_count610 obj.key_count += key_count611 else:612 obj = DungeonKeyObject(date, zone, do_type, user_count, times_count, key_count)613 objs.append(obj)614 obj_dict[do_type] = obj615 objs.sort(key=lambda x: x.do_type)616 for obj in objs:617 obj.get_str()618 return objs619# å¸é½å
°å¾·å°-éé¥å620def get_dungeon_gold_key_objs_list(db, date, zone):621 query_data = DungeonKey.objects.using(db).filter(date=date, zone=zone, key_id=settings.TABULATE_DUNGEON_GOLD_KEY_CODE)622 objs = []623 for data in query_data:624 do_type, user_count, times_count, key_count = data.do_type, data.user_count, data.times_count, data.key_count625 obj = DungeonKeyObject(date, zone, do_type, user_count, times_count, key_count)626 obj.get_str()627 objs.append(obj)628 objs.sort(key=lambda x: x.do_type)629 return objs630def get_dungeon_gold_key_summary_objs_list(db, date):631 zone = 'summary'632 query_data = DungeonKey.objects.using(db).filter(date=date, key_id=settings.TABULATE_DUNGEON_GOLD_KEY_CODE)633 objs = []634 obj_dict = {}635 for data in query_data:636 do_type, user_count, times_count, key_count = data.do_type, data.user_count, data.times_count, data.key_count637 if do_type in obj_dict:638 obj = obj_dict[do_type]639 obj.user_count += user_count640 obj.times_count += times_count641 obj.key_count += key_count642 else:643 obj = DungeonKeyObject(date, zone, do_type, user_count, times_count, key_count)644 objs.append(obj)645 obj_dict[do_type] = obj646 objs.sort(key=lambda x: x.do_type)647 for obj in objs:648 obj.get_str()649 return objs650# é»å¸å·æ°651class BmRefreshObject(object):652 def __init__(self, date, zone, money_type, amount, user_count, times_count):653 self.date = date654 self.zone = zone655 self.money_type = money_type656 self.amount = amount657 self.user_count = user_count658 self.times_count = times_count659 def get_str(self):660 self.date_str = _get_date_str(self.date)661 self.zone_str = settings.TABULATE_ZONE_NAME[self.zone]662 self.money_type_str = settings.TABULATE_BM_REFRESH_MONEY_TYPE_NAME[self.money_type]663 self.amount_str = _get_str_by_int(self.amount) 664 self.user_count_str = _get_str_by_int(self.user_count)665 self.times_count_str = _get_str_by_int(self.times_count)666def get_bm_refresh_objs_list(db, date, zone):667 query_data = BmRefresh.objects.using(db).filter(date=date, zone=zone)668 objs = []669 for data in query_data:670 money_type, amount, user_count, times_count = data.money_type, data.amount, data.user_count, data.times_count671 obj = BmRefreshObject(date, zone, money_type, amount, user_count, times_count)672 obj.get_str()673 objs.append(obj)674 objs.sort(key=lambda x: x.money_type)675 return objs676def get_bm_refresh_summary_objs_list(db, date):677 zone = 'summary'678 query_data = BmRefresh.objects.using(db).filter(date=date)679 objs = []680 obj_dict = {}681 for data in query_data:682 money_type, amount, user_count, times_count = data.money_type, data.amount, data.user_count, data.times_count683 if money_type in obj_dict:684 obj = obj_dict[money_type]685 obj.amount += amount686 obj.user_count += user_count687 obj.times_count += times_count688 else:689 obj = BmRefreshObject(date, zone, money_type, amount, user_count, times_count)690 objs.append(obj)691 obj_dict[money_type] = obj692 objs.sort(key=lambda x: x.money_type)693 for obj in objs:694 obj.get_str()695 return objs696# é»å¸è´ä¹°697class BmBuyObject(object):698 def __init__(self, date, zone, money_type, amount, user_count, times_count):699 self.date = date700 self.zone = zone701 self.money_type = money_type702 self.amount = amount703 self.user_count = user_count704 self.times_count = times_count705 def get_str(self):706 self.date_str = _get_date_str(self.date)707 self.zone_str = settings.TABULATE_ZONE_NAME[self.zone]708 self.money_type_str = settings.TABULATE_BM_BUY_MONEY_TYPE_NAME[self.money_type]709 self.amount_str = _get_str_by_int(self.amount) 710 self.user_count_str = _get_str_by_int(self.user_count)711 self.times_count_str = _get_str_by_int(self.times_count)712def get_bm_buy_objs_list(db, date, zone):713 query_data = BmBuy.objects.using(db).filter(date=date, zone=zone)714 objs = []715 for data in query_data:716 money_type, amount, user_count, times_count = data.money_type, data.amount, data.user_count, data.times_count717 obj = BmBuyObject(date, zone, money_type, amount, user_count, times_count)718 obj.get_str()719 objs.append(obj)720 objs.sort(key=lambda x: x.money_type)721 return objs722def get_bm_buy_summary_objs_list(db, date):723 zone = 'summary'724 query_data = BmBuy.objects.using(db).filter(date=date)725 objs = []726 obj_dict = {}727 for data in query_data:728 money_type, amount, user_count, times_count = data.money_type, data.amount, data.user_count, data.times_count729 if money_type in obj_dict:730 obj = obj_dict[money_type]731 obj.amount += amount732 obj.user_count += user_count733 obj.times_count += times_count734 else:735 obj = BmBuyObject(date, zone, money_type, amount, user_count, times_count)736 objs.append(obj)737 obj_dict[money_type] = obj738 objs.sort(key=lambda x: x.money_type)739 for obj in objs:740 obj.get_str()741 return objs742# é»å¸ç©åè´ä¹°æ
åµ743bm_goods_item_type_normal = {744 3: 'éå¸', #zel745 11:'é', #karma746 8: 'é»ç³', #dia747 2: 'åæ
ç¹', #friend_p748}749bm_goods_item_type_special = {750 7:'item', #BRV_ITEM_MST751 6:'unit', #BRV_UNIT_MST752}753def _get_key(elist):754 key = ''755 for e in elist:756 key += str(e) + ':'757 return key[:-1]758class BmGoodsObject(object):759 def __init__(self, date, zone, item_type, item_id, user_count, times_count, amount):760 self.date = date761 self.zone = zone762 self.item_type = item_type763 self.item_id = item_id764 self.user_count = user_count765 self.times_count = times_count766 self.amount = amount767 768 self.goods_key = _get_key([item_type, item_id])769 self.goods_str = None770 def get_str(self):771 self.date_str = _get_date_str(self.date)772 self.zone_str = settings.TABULATE_ZONE_NAME[self.zone]773 self.user_count_str = _get_str_by_int(self.user_count)774 self.times_count_str = _get_str_by_int(self.times_count)775 self.amount_str = _get_str_by_int(self.amount) 776def get_bm_goods_objs_list(db, date, zone):777 query_data = BmGoods.objects.using(db).filter(date=date, zone=zone)778 bm_goods_item_type_special_db = str(zone) + '_brave_cn_common'779 item_cache = {}780 unit_cache = {}781 objs = []782 for data in query_data:783 item_type, item_id, user_count, times_count, amount = data.item_type, data.item_id, data.user_count, data.times_count, data.amount784 goods_key = _get_key([item_type, item_id])785 obj = BmGoodsObject(date, zone, item_type, item_id, user_count, times_count, amount)786 obj.get_str()787 if item_type in bm_goods_item_type_normal:788 obj.goods_str = bm_goods_item_type_normal[item_id]789 elif item_type in bm_goods_item_type_special:790 if item_type == 7:791 if not item_cache:792 cache_data = BrvItemMst.objects.using(bm_goods_item_type_special_db)793 for c_data in cache_data:794 item_cache[c_data.ITEM_ID] = c_data.ITEM_NAME795 obj.goods_str = item_cache[item_id] if item_id in item_cache else goods_key796 elif item_type ==6:797 if not unit_cache:798 cache_data = BrvUnitMst.objects.using(bm_goods_item_type_special_db)799 for c_data in cache_data:800 unit_cache[c_data.UNIT_ID] = c_data.UNIT_NAME801 obj.goods_str = unit_cache[item_id] if item_id in unit_cache else goods_key802 else:803 obj.goods_str = goods_key804 else:805 obj.goods_str = goods_key806 objs.append(obj)807 return objs808def get_bm_goods_summary_objs_list(db, date):809 zone = 'summary'810 query_data = BmGoods.objects.using(db).filter(date=date)811 item_cache_dict = {}812 unit_cache_dict = {}813 objs = []814 obj_dict = {}815 for data in query_data:816 item_type, item_id, user_count, times_count, amount = data.item_type, data.item_id, data.user_count, data.times_count, data.amount817 818 bm_goods_item_type_special_db = str(data.zone) + '_brave_cn_common'819 820 goods_key = _get_key([item_type, item_id])821 if goods_key in obj_dict:822 obj = obj_dict[goods_key]823 obj.user_count += user_count824 obj.times_count += times_count825 obj.amount += amount826 else:827 obj = BmGoodsObject(date, zone, item_type, item_id, user_count, times_count, amount)828 objs.append(obj)829 obj_dict[goods_key] = obj830 if item_type in bm_goods_item_type_normal:831 obj.goods_str = bm_goods_item_type_normal[item_id]832 elif item_type in bm_goods_item_type_special:833 if item_type == 7:834 if data.zone not in item_cache_dict:835 item_cache_dict[data.zone] = {}836 item_cache = item_cache_dict[data.zone]837 cache_data = BrvItemMst.objects.using(bm_goods_item_type_special_db)838 for c_data in cache_data:839 item_cache[c_data.ITEM_ID] = c_data.ITEM_NAME840 item_cache = item_cache_dict[data.zone]841 obj.goods_str = item_cache[item_id] if item_id in item_cache else goods_key842 elif item_type ==6:843 if data.zone not in unit_cache_dict:844 unit_cache_dict[data.zone] = {}845 unit_cache = unit_cache_dict[data.zone]846 cache_data = BrvUnitMst.objects.using(bm_goods_item_type_special_db)847 for c_data in cache_data:848 unit_cache[c_data.UNIT_ID] = c_data.UNIT_NAME849 unit_cache = unit_cache_dict[data.zone]850 obj.goods_str = unit_cache[item_id] if item_id in unit_cache else goods_key851 else:852 obj.goods_str = goods_key853 else:854 obj.goods_str = goods_key855 for obj in objs:856 obj.get_str()...
sort_projects.py
Source:sort_projects.py
1import operator2projects = [{3 "name": "Apertium",4 "url": "http://www.ohloh.net/p/apertium.xml",5 "homepage_url": "http://www.apertium.org/",6 "user_count": "10",7 "average_rating": "5.0",8 "rating_count": "6",9 "review_count": "0"10},11{12 "name": "Etherpad Lite",13 "url": "http://www.ohloh.net/p/etherpad_lite.xml",14 "homepage_url": "http://etherpad.org",15 "user_count": "4",16 "average_rating": "5.0",17 "rating_count": "1",18 "review_count": "0"19},20{21 "name": "Etherpad Lite",22 "url": "http://www.ohloh.net/p/etherpad_lite.xml",23 "homepage_url": "http://etherpad.org",24 "user_count": "4",25 "average_rating": "5.0",26 "rating_count": "1",27 "review_count": "0"28},29{30 "name": "django-myerscms",31 "url": "http://www.ohloh.net/p/django-myerscms.xml",32 "homepage_url": "http://code.google.com/p/django-myerscms",33 "user_count": "0",34 "average_rating": "None",35 "rating_count": "0",36 "review_count": "0"37},38{39 "name": "ownCloud",40 "url": "http://www.ohloh.net/p/ownCloud.xml",41 "homepage_url": "http://ownCloud.org",42 "user_count": "28",43 "average_rating": "5.0",44 "rating_count": "5",45 "review_count": "0"46},47{48 "name": "Globus Toolkit",49 "url": "http://www.ohloh.net/p/6008.xml",50 "homepage_url": "http://www.globus.org",51 "user_count": "2",52 "average_rating": "3.0",53 "rating_count": "2",54 "review_count": "0"55},56{57 "name": "seafile",58 "url": "http://www.ohloh.net/p/seafile.xml",59 "homepage_url": "http://seafile.com",60 "user_count": "1",61 "average_rating": "5.0",62 "rating_count": "1",63 "review_count": "0"64},65{66 "name": "FlowPlayer",67 "url": "http://www.ohloh.net/p/flowplayer.xml",68 "homepage_url": "http://flowplayer.org",69 "user_count": "9",70 "average_rating": "4.25",71 "rating_count": "4",72 "review_count": "1"73},74{75 "name": "OpenNebula",76 "url": "http://www.ohloh.net/p/opennebula.xml",77 "homepage_url": "http://opennebula.org",78 "user_count": "14",79 "average_rating": "4.28571",80 "rating_count": "7",81 "review_count": "0"82},83{84 "name": "NoseRub",85 "url": "http://www.ohloh.net/p/NoseRub.xml",86 "homepage_url": "http://www.noserub.com",87 "user_count": "7",88 "average_rating": "4.75",89 "rating_count": "4",90 "review_count": "0"91},92{93 "name": "Gwibber",94 "url": "http://www.ohloh.net/p/gwibber.xml",95 "homepage_url": "https://launchpad.net/gwibber",96 "user_count": "35",97 "average_rating": "4.11111",98 "rating_count": "18",99 "review_count": "0"100},101{102},103{104 "name": "MediaWiki",105 "url": "http://www.ohloh.net/p/mediawiki.xml",106 "homepage_url": "http://www.mediawiki.org/",107 "user_count": "799",108 "average_rating": "4.2438",109 "rating_count": "242",110 "review_count": "4"111},112{113 "name": "iFolder",114 "url": "http://www.ohloh.net/p/8386.xml",115 "homepage_url": "http://www.ifolder.com",116 "user_count": "3",117 "average_rating": "None",118 "rating_count": "0",119 "review_count": "0"120},121{122 "name": "Piwigo",123 "url": "http://www.ohloh.net/p/piwigo.xml",124 "homepage_url": "http://piwigo.org",125 "user_count": "28",126 "average_rating": "4.9",127 "rating_count": "20",128 "review_count": "1"129},130{131 "name": "AppScale",132 "url": "http://www.ohloh.net/p/appscale.xml",133 "homepage_url": "http://appscale.cs.ucsb.edu/",134 "user_count": "4",135 "average_rating": "5.0",136 "rating_count": "1",137 "review_count": "0"138},139{140},141{142 "name": "DokuWiki",143 "url": "http://www.ohloh.net/p/dokuwiki.xml",144 "homepage_url": "http://www.dokuwiki.org/",145 "user_count": "205",146 "average_rating": "4.53488",147 "rating_count": "86",148 "review_count": "5"149},150{151 "name": "ocp-subsystems",152 "url": "http://www.ohloh.net/p/ocp-subsystems.xml",153 "homepage_url": "http://code.google.com/p/ocp-subsystems",154 "user_count": "0",155 "average_rating": "None",156 "rating_count": "0",157 "review_count": "0"158},159{160 "name": "MiniG",161 "url": "http://www.ohloh.net/p/12624.xml",162 "homepage_url": "http://minig.org/",163 "user_count": "56",164 "average_rating": "4.71429",165 "rating_count": "7",166 "review_count": "0"167},168{169 "name": "Open Journal Systems",170 "url": "http://www.ohloh.net/p/ojs2.xml",171 "homepage_url": "http://pkp.sfu.ca/ojs",172 "user_count": "6",173 "average_rating": "5.0",174 "rating_count": "2",175 "review_count": "0"176},177{178 "name": "Friendica",179 "url": "http://www.ohloh.net/p/friendica.xml",180 "homepage_url": "http://friendica.com/",181 "user_count": "9",182 "average_rating": "5.0",183 "rating_count": "3",184 "review_count": "0"185},186{187 "name": "TubePress",188 "url": "http://www.ohloh.net/p/tubepress.xml",189 "homepage_url": "http://tubepress.org",190 "user_count": "1",191 "average_rating": "5.0",192 "rating_count": "1",193 "review_count": "0"194},195{196 "name": "Zimbra Collaboration Suite",197 "url": "http://www.ohloh.net/p/zimbra.xml",198 "homepage_url": "http://www.zimbra.com/community/downloads.html",199 "user_count": "56",200 "average_rating": "3.95",201 "rating_count": "20",202 "review_count": "2"203},204{205 "name": "WordPress",206 "url": "http://www.ohloh.net/p/wordpress.xml",207 "homepage_url": "http://wordpress.org/",208 "user_count": "1528",209 "average_rating": "4.31718",210 "rating_count": "454",211 "review_count": "6"212},213{214 "name": "bbPress",215 "url": "http://www.ohloh.net/p/bbpress.xml",216 "homepage_url": "http://bbpress.org/",217 "user_count": "27",218 "average_rating": "4.3",219 "rating_count": "10",220 "review_count": "0"221},222{223 "name": "Gallery 2",224 "url": "http://www.ohloh.net/p/gallery.xml",225 "homepage_url": "http://gallery.menalto.com",226 "user_count": "147",227 "average_rating": "4.26",228 "rating_count": "50",229 "review_count": "4",230},231{232 "name": "Elgg",233 "url": "http://www.ohloh.net/p/elgg.xml",234 "homepage_url": "http://elgg.org/",235 "user_count": "37",236 "average_rating": "4.0",237 "rating_count": "11",238 "review_count": "2"239},240{241 "name": "Piwik",242 "url": "http://www.ohloh.net/p/piwik.xml",243 "homepage_url": "http://piwik.org",244 "user_count": "40",245 "average_rating": "4.58824",246 "rating_count": "17",247 "review_count": "0"248},249{250 "name": "Funambol Client for Mozilla Thunderbird",251 "url": "http://www.ohloh.net/p/funbird.xml",252 "homepage_url": "https://mozilla-plugin.forge.funambol.org/",253 "user_count": "926",254 "average_rating": "4.66667",255 "rating_count": "9",256 "review_count": "0"257},258{259 "name": "Funambol Client for Mozilla Thunderbird",260 "url": "http://www.ohloh.net/p/funbird.xml",261 "homepage_url": "https://mozilla-plugin.forge.funambol.org/",262 "user_count": "926",263 "average_rating": "4.66667",264 "rating_count": "9",265 "review_count": "0"266},267{268 "name": "Adium",269 "url": "http://www.ohloh.net/p/adium.xml",270 "homepage_url": "http://www.adium.im/",271 "user_count": "446",272 "average_rating": "4.45517",273 "rating_count": "145",274 "review_count": "2"275},276{277 "name": "Phorum",278 "url": "http://www.ohloh.net/p/phorum.xml",279 "homepage_url": "http://www.phorum.org",280 "user_count": "8",281 "average_rating": "4.85714",282 "rating_count": "7",283 "review_count": "0"284},285{286 "name": "phpBB",287 "url": "http://www.ohloh.net/p/phpbb.xml",288 "homepage_url": "http://www.phpbb.com/",289 "user_count": "879",290 "average_rating": "4.1694",291 "rating_count": "182",292 "review_count": "4"293},294{295 "name": "Mailman",296 "url": "http://www.ohloh.net/p/mailman.xml",297 "homepage_url": "http://www.list.org",298 "user_count": "205",299 "average_rating": "3.625",300 "rating_count": "48",301 "review_count": "0"302},303{304 "name": "Eucalyptus",305 "url": "http://www.ohloh.net/p/eucalyptus.xml",306 "homepage_url": "http://www.eucalyptus.com",307 "user_count": "18",308 "average_rating": "4.33333",309 "rating_count": "9",310 "review_count": "0"311},312{313 "name": "Vanilla Forums",314 "url": "http://www.ohloh.net/p/vanillaforums.xml",315 "homepage_url": "http://vanillaforums.org/",316 "user_count": "21",317 "average_rating": "3.92857",318 "rating_count": "14",319 "review_count": "2"320},321{322 "name": "FluxBB",323 "url": "http://www.ohloh.net/p/FluxBB.xml",324 "homepage_url": "http://fluxbb.org",325 "user_count": "16",326 "average_rating": "4.71429",327 "rating_count": "14",328 "review_count": "0"329},330{331 "name": "StatusNet",332 "url": "http://www.ohloh.net/p/statusnet.xml",333 "homepage_url": "http://status.net",334 "user_count": "36",335 "average_rating": "4.63636",336 "rating_count": "22",337 "review_count": "0"338},339{340 "name": "Roundcube Webmail",341 "url": "http://www.ohloh.net/p/roundcube.xml",342 "homepage_url": "http://www.roundcube.net",343 "user_count": "214",344 "average_rating": "4.32353",345 "rating_count": "68",346 "review_count": "4"347},348{349},350{351 "name": "Plumi",352 "url": "http://www.ohloh.net/p/plumi.xml",353 "homepage_url": "http://www.plumi.org",354 "user_count": "5",355 "average_rating": "4.6",356 "rating_count": "5",357 "review_count": "0"358},359{360 "name": "Twitter/identi.ca micro-blogging bot",361 "url": "http://www.ohloh.net/p/mb-chatbot.xml",362 "homepage_url": "http://sourceforge.net/projects/mb-chatbot/",363 "user_count": "0",364 "average_rating": "None",365 "rating_count": "0",366 "review_count": "0"367},368{369 "name": "libre.fm",370 "url": "http://www.ohloh.net/p/librefm.xml",371 "homepage_url": "http://libre.fm",372 "user_count": "15",373 "average_rating": "4.0",374 "rating_count": "8",375 "review_count": "0"376},377{378 "name": "OpenLayers",379 "url": "http://www.ohloh.net/p/openlayers.xml",380 "homepage_url": "http://openlayers.org/",381 "user_count": "147",382 "average_rating": "4.7",383 "rating_count": "50",384 "review_count": "2"385},386{387 "name": "phpGroupWare",388 "url": "http://www.ohloh.net/p/phpgroupware.xml",389 "homepage_url": "http://phpgroupware.org",390 "user_count": "5",391 "average_rating": "2.0",392 "rating_count": "4",393 "review_count": "0"394},395{396 "name": "Feng Office",397 "url": "http://www.ohloh.net/p/fengoffice.xml",398 "homepage_url": "http://www.opengoo.org/",399 "user_count": "16",400 "average_rating": "4.08333",401 "rating_count": "12",402 "review_count": "1"403},404{405 "name": "SquirrelMail",406 "url": "http://www.ohloh.net/p/squirrelmail.xml",407 "homepage_url": "http://squirrelmail.org",408 "user_count": "134",409 "average_rating": "3.72727",410 "rating_count": "33",411 "review_count": "3"412},413{414},415{416},417{418 "name": "LimeSurvey",419 "url": "http://www.ohloh.net/p/limesurvey.xml",420 "homepage_url": "http://www.limesurvey.org",421 "user_count": "36",422 "average_rating": "4.0",423 "rating_count": "16",424 "review_count": "0"425},426{427 "name": "Cheetah News",428 "url": "http://www.ohloh.net/p/cheetah-news.xml",429 "homepage_url": "http://www.cheetah-news.com/",430 "user_count": "2",431 "average_rating": "None",432 "rating_count": "0",433 "review_count": "0"434},435{436 "name": "surforce-meneame",437 "url": "http://www.ohloh.net/p/surforce-meneame.xml",438 "homepage_url": "http://code.google.com/p/surforce-meneame",439 "user_count": "0",440 "average_rating": "None",441 "rating_count": "0",442 "review_count": "0"443},444{445 "name": "Vote Up/Down",446 "url": "http://www.ohloh.net/p/vote_up_down.xml",447 "homepage_url": "http://drupal.org/project/vote_up_down",448 "user_count": "5",449 "average_rating": "3.0",450 "rating_count": "1",451 "review_count": "0"452},453{454},455{456 "name": "Diaspora",457 "url": "http://www.ohloh.net/p/diaspora.xml",458 "homepage_url": "http://joindiaspora.com/",459 "user_count": "25",460 "average_rating": "4.25",461 "rating_count": "8",462 "review_count": "0"463},464{465 "name": "SemanticScuttle",466 "url": "http://www.ohloh.net/p/semanticscuttle.xml",467 "homepage_url": "http://semanticscuttle.sourceforge.net/",468 "user_count": "4",469 "average_rating": "5.0",470 "rating_count": "1",471 "review_count": "0"472},473{474 "name": "Rubric",475 "url": "http://www.ohloh.net/p/8244.xml",476 "homepage_url": "http://search.cpan.org/dist/Rubric/",477 "user_count": "2",478 "average_rating": "4.0",479 "rating_count": "1",480 "review_count": "0"481},482{483 "name": "Connotea",484 "url": "http://www.ohloh.net/p/5107.xml",485 "homepage_url": "http://www.connotea.org/",486 "user_count": "1",487 "average_rating": "3.0",488 "rating_count": "1",489 "review_count": "0"490},491{492 "name": "ShiftSpace",493 "url": "http://www.ohloh.net/p/shiftspace.xml",494 "homepage_url": "http://www.ShiftSpace.org",495 "user_count": "4",496 "average_rating": "5.0",497 "rating_count": "2",498 "review_count": "0"499},500{501},502{503 "name": "Drupal (contributions)",504 "url": "http://www.ohloh.net/p/drupal-contributions.xml",505 "homepage_url": "http://drupal.org/",506 "user_count": "314",507 "average_rating": "4.31313",508 "rating_count": "99",509 "review_count": "4"510},511{512 "name": "twitterizer",513 "url": "http://www.ohloh.net/p/twitterizer.xml",514 "homepage_url": "http://www.twitterizer.net/",515 "user_count": "79",516 "average_rating": "4.7",517 "rating_count": "10",518 "review_count": "1"519},520{521 "name": "Tiki Wiki CMS Groupware",522 "url": "http://www.ohloh.net/p/tikiwiki.xml",523 "homepage_url": "http://tiki.org",524 "user_count": "140",525 "average_rating": "4.36364",526 "rating_count": "66",527 "review_count": "11"528},529{530},531{532 "name": "eyeOS",533 "url": "http://www.ohloh.net/p/eyeos.xml",534 "homepage_url": "http://www.eyeos.org",535 "user_count": "24",536 "average_rating": "4.71429",537 "rating_count": "14",538 "review_count": "1"539},540{541 "name": "croqodile",542 "url": "http://www.ohloh.net/p/croqodile.xml",543 "homepage_url": "http://code.google.com/p/croqodile",544 "user_count": "0",545 "average_rating": "None",546 "rating_count": "0",547 "review_count": "0"548},549{550 "name": "OpenSimulator",551 "url": "http://www.ohloh.net/p/opensimulator.xml",552 "homepage_url": "http://www.opensimulator.org/",553 "user_count": "55",554 "average_rating": "4.71429",555 "rating_count": "21",556 "review_count": "0"557}]558print "Projects:", len(projects)559prMap = {}560for p in projects:561 if 'name' in p:562 prMap[p['name']] = int(p['user_count'])563 564sortedPrj = sorted(prMap.iteritems(), key=operator.itemgetter(1))565sortedPrj.reverse()566cnt=1567for p in sortedPrj:568 print cnt, p...
csv_chat.py
Source:csv_chat.py
1from collections import UserList2from pprint import pprint3from django.core.management.base import BaseCommand4from commands.models import user_details5from .functions_file.function_msg import *6import pandas as pd 7class Command(BaseCommand):8 help = 'send message as per csv'9 def add_arguments(self, parser):10 parser.add_argument('group',type=str,help = 'Group name')11 12 def handle(self,*args, **kwargs):13 group = kwargs['group']14 data = user_details.objects.all()15 data = [[i.number,i.api_id,i.api_hash] for i in data]16 data_length = len(data)17 chat = pd.read_csv('chat.csv')18 username = chat['Username']19 conversation = chat['Dialogue']20 chat_zip = zip(username,conversation)21 user_count = 022 dict = {}23 banned = False24 username_list = []25 banned = False26 for i in username:27 if not isinstance(i,float):28 i = i.replace(' ','')29 if i != '':30 if not i in username_list:31 username_list.append(i)32 if data_length < len(username_list):33 print('There is not enough user in Data base as required users to start this chat')34 else:35 for i in username_list:36 if not i in dict :37 user_cred = True38 while user_cred == True:39 banned = user_banned(data[user_count][0],data[user_count][1],data[user_count][2])40 if data_length <= user_count:41 print('not enough user')42 user_cred = False43 else:44 if not banned:45 dict [i] = {46 'number' : data[user_count][0],47 'apiid' : data[user_count][1],48 'apihash' : data[user_count][2]49 }50 print(user_count)51 user_cred = False52 user_count +=153 print(dict)54 55 if len(username_list) > len(dict):56 print('There is not enough users in database to send messages')57 else: 58 print(username_list)59 for i,ia in chat_zip:60 if isinstance(i,str):61 i = i.replace(' ','')62 if not i in dict:63 dict [i] = {64 'number' : data[user_count][0],65 'apiid' : data[user_count][1],66 'apihash' : data[user_count][2]67 }68 user_count +=169 70 number = dict[i]['number']71 id = dict[i]['apiid']72 hash = dict[i]['apihash'] 73 if number and id and hash:74 # client = TelegramClient(f'./sessions/{number}',id,hash)75 banned = user_banned(number,id,hash)76 if banned:77 dict[i] = {78 'number' : data[user_count][0],79 'apiid' : data[user_count][1],80 'apihash' : data[user_count][2]81 }82 user_count +=183 banned = False84 script_chat(i,number,id,hash,ia,group)85 pprint(dict)...
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!!