Beispiel #1
0
def statistic_page():
    stats = Statistics(app.config['dsn'])
    aths = Athletes(app.config['dsn'])
    if request.method == 'GET':
        now = datetime.datetime.now()
        statlist = stats.get_statisticlist()
        athlist = aths.get_athletlist()
        return render_template('statistics.html', StatisticList = statlist,AthletList = athlist, current_time=now.ctime())
    elif 'statistics_to_delete' in request.form:
        id_statistics = request.form.getlist('statistics_to_delete')
        for id_statistic in id_statistics:
            stats.delete_statistic(id_statistic)
        return redirect(url_for('statistic_page'))
    elif 'statistics_to_add' in request.form:
        id_athletes = request.form.getlist('statistics_to_add')
        for id_athlete in id_athletes:
            stats.add_statistic(request.form['distance'], request.form['time'],id_athlete)
        return redirect(url_for('statistic_page'))
    elif 'statistics_to_update' in request.form:
        stats.update_statistic(request.form['distance'], request.form['time'],request.form['id_statistic'])
        return redirect(url_for('statistic_page'))
    elif 'statistics_to_search' in request.form:
            searchList = stats.search_statistic(request.form['name']);
            now = datetime.datetime.now()
            statlist = stats.get_statisticlist()
            athlist = aths.get_athletlist()
            return render_template('statistics.html', StatisticList = statlist, SearchList = searchList,AthletList = athlist, current_time=now.ctime())
Beispiel #2
0
 def get(self):
     ip = self.request.remote_addr
     uid = 'notfound'
     url = self.request.uri
     user_agent = self.request.headers.get('User-Agent','none')
     new = Statistics(uid=uid,url=url,user_agent = user_agent, ip=ip,mtime=datetime.datetime.utcnow())
     new.put()
     self.redirect('https://www.google.com')
 def do_stats(self, fp, records):
     stats = Statistics([StatisticsAuthorNameColumn('Name', lambda x : x.author)])
     stats.process_records(records.comments, [
         StatisticsCountColumn('Comments', lambda x : x.timestamp)
         ])
     stats.process_records(records.technical_comments, [
         StatisticsCountColumn('Technical', lambda x : x.timestamp)
         ])
     stats.process_records(records.votes, [
         StatisticsCountColumn('Votes', lambda x : x.timestamp)
         ])
     stats.print_stats(fp, sort_by='Comments')
Beispiel #4
0
 def step3(self):
     resultDir = self.createDir(str(3))
     (match, no_match) = self.createResultFile(resultDir)
 
     success = 0
     failed  = 0    
     for element in self.table1.find({'ji': {'$ne': ""}}):
         ji = element['ji']
         gongLiNian = int(element['gongLiNian'])
         gongLiNianScope = [str(gongLiNian-1), str(gongLiNian), str(gongLiNian+1)]
         res = self.table2.find_one({'guanZhi' : element['guanZhi'], 
                                      'gongLiNian' : {'$in': gongLiNianScope},
                                     'name'    : element['name'],
                                     'minZu'   : element['minZu']})
     
         if res and (len(ji) > 0) and (Statistics.convertJi(self, res['ji']) in self.jiScope(ji)) and (element['qiFen'] == res['qiFen'] or element['qiFen'] == res['qiFenHuo']):
             match.write(self.formatElement(element))
             success += 1
         else:
             no_match.write(self.formatElement(element))
             failed += 1
     failed = self.total - success
     result = (success, success/self.total, failed, failed/self.total)    
     self.logResult(3, result) 
     return result
Beispiel #5
0
 def __init__(self, dbName1, dbName2, rootDir=None):
     Statistics.__init__(self, dbName1, dbName2, rootDir)
     self.total = self.table1.count()
     self.rootDir = os.path.join(self.rootDir, u"步骤三数据库数据的匹配程度")
     if not os.path.exists(self.rootDir):
         os.mkdir(self.rootDir)
     
     self.rootDir = os.path.join(self.rootDir, r"3.数据库1、2与数据库3的比对")    
     if not os.path.exists(self.rootDir):
         os.mkdir(self.rootDir)
     
     self.rootDir = os.path.join(self.rootDir, r"2.数据库2与数据库3对比")    
     if not os.path.exists(self.rootDir):
         os.mkdir(self.rootDir)
         
     self.logger = logging.getLogger('CompareDB2AndDB3')
Beispiel #6
0
 def getter(self):
     ans = Statistics.by_id(self.data['statistics_id'])
     if ans is None:
         ans = Statistics()
         self.data['statistics_id'] = ans._id
         return ans, True
     return ans
Beispiel #7
0
 def __init__(self, dbName1, dbName2, rootDir = None):
     Statistics.__init__(self, dbName1, dbName2, rootDir)
     self.total = self.table1.count()
     self.rootDir = os.path.join(self.rootDir, u"步骤三数据库数据的匹配程度")
     if not os.path.exists(self.rootDir):
         os.mkdir(self.rootDir)
     
     self.rootDir = os.path.join(self.rootDir, u"2.不考虑公历年")    
     if not os.path.exists(self.rootDir):
         os.mkdir(self.rootDir)
     
     self.rootDir = os.path.join(self.rootDir, u"1.不考虑季节")    
     if not os.path.exists(self.rootDir):
         os.mkdir(self.rootDir)
             
     self.logger = logging.getLogger(u'不考虑季')
Beispiel #8
0
    def get(self):
        sta = Statistics.all()
#        sta.order("-mtime")
        for s in sta:
            if not s.addr:
                s.addr = addr.ip2addr(s.ip)
                s.put()
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write('ok')
Beispiel #9
0
 def get(self):
     ip = self.request.remote_addr
     user_agent = self.request.headers.get('User-Agent','none')
     try:
         url = self.request.query_string
         logging.info(url)
         uid, url = url.split('&', 1)
     except Exception as e:
         logging.error(e)
         uid = 'err'
         new = Statistics(uid=uid,url=url,user_agent = user_agent, ip=ip,mtime=datetime.datetime.utcnow())
         url = 'https://www.google.com'
     else:
         new = Statistics(uid=uid,url=url,user_agent = user_agent, ip=ip,mtime=datetime.datetime.utcnow())
     new.put()
     if not url.startswith('http'):
         url = 'http://' + url
     self.redirect(str(url))
Beispiel #10
0
    def create_banks(self):
        """
        Creates bank objects, stores them in self.banks, and registers them in a self.bank_to_id.
        A part of all banks follows a Pareto distribution, all others a log-normal distribution, in asset size.
        All created banks are registered in the dictionary self.id_to_bank.
        :rtype : None
        """
        for n in xrange(0, NUMBER_OF_BANKS_LOGNORMAL):
            bank_size = Statistics.generate_lognormal_number(LOGNORMAL_MEAN, LOGNOMRAL_STDEV)
            bank = Bank(bank_size)
            self.banks.append(bank)
            self.id_to_bank[id(bank)] = bank

        for n in xrange(0, NUMBER_OF_BANKS_PARETO):
            bank_size = Statistics.generate_pareto_number(PARETO_SCALE, PARETO_SHAPE)
            bank = Bank(bank_size)
            self.banks.append(bank)
            self.id_to_bank[id(bank)] = bank
Beispiel #11
0
def main():
    config = Configuration()
    config.load("config/config.json")

    emailFiles = listEmailFiles(config.gmailRoot)
    stats = Statistics()

    progress = ProgressBar(
        widgets=["Parsing Mail: ", Percentage(), " ", Bar(), " ", ETA()], maxval=len(emailFiles)
    ).start()

    for filename in emailFiles:
        progress.update(progress.currval + 1)
        updateStatistics(stats, config, filename)

    progress.finish()

    stats.save()
 def do_stats(self, fp, records):
     stats = Statistics([StatisticsAuthorNameColumn('Name', lambda x : x.author)])
     stats.process_records(records.change_activity, [
         StatisticsCountColumn('Created', lambda x : x.created_on),
         StatisticsCountColumn('Merged', lambda x : x.merged_on),
         StatisticsCountColumn('Abandoned', lambda x : x.abandoned_on),
         StatisticsCountColumn('Both', lambda x : x.created_on and x.closed_on)
         ])
     stats.process_records(records.comments, [
         StatisticsDistinctCountColumn('Commented', lambda x : x.change if x.timestamp else None)
         ])
     stats.process_records(records.votes, [
         StatisticsDistinctCountColumn('Voted', lambda x : x.change if x.timestamp else None)
         ])
     stats.print_stats(fp, sort_by='Voted')
Beispiel #13
0
async def handle_1_TV_raffle(type, num, real_roomid, raffleid):
    await asyncio.sleep(random.uniform(0, min(num, 30)))
    response2 = await bilibili().get_gift_of_TV(type, real_roomid, raffleid)
    Printer().printer(f"参与了房间 {real_roomid} 的广播抽奖", "Lottery", "cyan")
    json_response2 = await response2.json(content_type=None)
    Printer().printer(f"房间 {real_roomid} 广播道具抽奖状态: {json_response2['msg']}", "Lottery", "cyan")
    if json_response2['code'] == 0:
        Statistics().append_to_TVlist(raffleid, real_roomid)
    else:
        print(json_response2)
 def do_stats(self, fp, records):
     stats = Statistics([StatisticsAuthorNameColumn('Name', lambda x : x.author)])
     stats.process_records(records.open_changes, [
         StatisticsCountColumn('Open', lambda x : True),
         StatisticsCountColumn('RFC/WIP', lambda x : x.is_rfc_wip),
         StatisticsCountColumn('-Verified',
             lambda x : not x.is_rfc_wip and not x.is_verified),
         StatisticsCountColumn('-Review',
             lambda x : not x.is_rfc_wip and x.is_verified and x.is_downvoted),
         StatisticsCountColumn('Approved',
             lambda x : not x.is_rfc_wip and x.is_verified and x.is_approved),
         StatisticsCountColumn('+Review',
             lambda x : not x.is_rfc_wip and x.is_verified and not x.is_approved and x.is_upvoted),
         StatisticsCountColumn('Comments',
             lambda x : not x.is_rfc_wip and x.is_verified and not x.is_upvoted and not x.is_downvoted and x.has_comments),
         StatisticsCountColumn('Nothing',
             lambda x : not x.is_rfc_wip and x.is_verified and not x.has_comments)
         ])
     stats.print_stats(fp, sort_by='Open')
Beispiel #15
0
    def __init__(self):

        # Load data
        parse_start = time.perf_counter_ns()
        self.storage = GazPointStorageJson("data.json")
        parse_end = time.perf_counter_ns()

        load_start = time.perf_counter_ns()
        self.gaz_data = GazPointData(self.storage.load_gaz_points())
        load_end = time.perf_counter_ns()

        stats_start = time.perf_counter_ns()
        self.statistics = Statistics(self.gaz_data)
        self.viz = Visualisation()
        stats_end = time.perf_counter_ns()

        print("Json parsing time : {}".format(parse_end-parse_start))
        print("Data loading time : {}".format(load_end-load_start))
        print("Stats loading time : {}".format(stats_end-stats_start))
 def do_stats(self, fp, records):
     stats = Statistics([StatisticsAuthorNameColumn('Name', lambda x : x.author)])
     stats.process_records(records.open_comments, [
         StatisticsDistinctCountColumn('Commented', lambda x : x.change)
         ])
     stats.process_records(records.open_votes, [
         StatisticsDistinctCountColumn('Voted', lambda x : x.change)
         ])
     stats.print_stats(fp, sort_by='Commented')
Beispiel #17
0
    def __init__(self, genome):
        """ The GPopulation Class creator """

        if isinstance(genome, GPopulation):

            self.oneSelfGenome = genome.oneSelfGenome
            self.internalPop = []
            self.internalPopRaw = []
            self.popSize = genome.popSize
            self.sortType = genome.sortType
            self.sorted = False
            self.minimax = genome.minimax
            self.scaleMethod = genome.scaleMethod
            self.allSlots = [self.scaleMethod]

            self.internalParams = genome.internalParams
            self.multiProcessing = genome.multiProcessing

            self.statted = False
            self.stats = Statistics()
            return

        log.debug("New population instance, %s class genomes.",
                  genome.__class__.__name__)

        self.oneSelfGenome = genome
        self.internalPop = []
        self.internalPopRaw = []
        self.popSize = 0
        self.sortType = constants.CDefPopSortType
        self.sorted = False
        self.minimax = constants.CDefPopMinimax
        self.scaleMethod = FunctionSlot("Scale Method")
        self.scaleMethod.set(constants.CDefPopScale)
        self.allSlots = [self.scaleMethod]

        self.internalParams = {}
        self.multiProcessing = (False, False, None)

        # Statistics
        self.statted = False
        self.stats = Statistics()
Beispiel #18
0
    def __init__(self, genome):

        """ The GPopulation Class creator """

        if isinstance(genome, GPopulation):

            self.oneSelfGenome = genome.oneSelfGenome
            self.internalPop = []
            self.internalPopRaw = []
            self.popSize = genome.popSize
            self.sortType = genome.sortType
            self.sorted = False
            self.minimax = genome.minimax
            self.scaleMethod = genome.scaleMethod
            self.allSlots = [self.scaleMethod]

            self.internalParams = genome.internalParams
            self.multiProcessing = genome.multiProcessing

            self.statted = False
            self.stats = Statistics()
            return

        log.debug("New population instance, %s class genomes.", genome.__class__.__name__)

        self.oneSelfGenome = genome
        self.internalPop = []
        self.internalPopRaw = []
        self.popSize = 0
        self.sortType = constants.CDefPopSortType
        self.sorted = False
        self.minimax = constants.CDefPopMinimax
        self.scaleMethod = FunctionSlot("Scale Method")
        self.scaleMethod.set(constants.CDefPopScale)
        self.allSlots = [self.scaleMethod]

        self.internalParams = {}
        self.multiProcessing = (False, False, None)

        # Statistics
        self.statted = False
        self.stats = Statistics()
Beispiel #19
0
def train(args):
    # Init gym env
    env = Environment(args)
    agent = Q_Agent(env, args)
    stats = Statistics(None, agent, env, args)
    if not args.load_model.isspace(): agent.loadModel(args.load_model)

    # Train agent
    try:
        for epoch in range(args.epochs):
            print 'Epoch #%d' % (epoch + 1)

            if args.test_eps > 0:
                print 'Testing for %d steps' % args.test_eps
                agent.test(args.test_eps, render=args.render)
                stats.log()

        print 'Done'
    except KeyboardInterrupt:
        print 'Caught keyboard interrupt, stopping run...'
Beispiel #20
0
class TestStatistics(unittest.TestCase):
    def setUp(self):
        self.statistics = Statistics(PlayerReaderStub())

    def test_search_returns_a_player(self):
        player = self.statistics.search("Semenko")
        self.assertEqual(player.__str__(), "Semenko EDM 4 + 12 = 16")

    def test_search_returns_None_if_no_such_player(self):
        player = self.statistics.search("Kukko Pärssinen")
        self.assertEqual(player, None)

    def test_team_search_returns_valid_team(self):
        team = self.statistics.team("PIT")
        self.assertEqual(team[0].__str__(), "Lemieux PIT 45 + 54 = 99")
    
    def test_top_scorers_first_is_the_most_points(self):
        scorers = self.statistics.top_scorers(1)
        self.assertEqual(scorers[0].points, 124)
        self.assertEqual(scorers[0].__str__(), "Gretzky EDM 35 + 89 = 124")
Beispiel #21
0
class TestStatistics(unittest.TestCase):
    def setUp(self):
        # annetaan Statistics-luokan oliolle "stub"-luokan olio
        self.statistics = Statistics(PlayerReaderStub())

    def test_konstruktori_luo_statistiikat(self):
        edmonton = self.statistics.team("EDM")
        sizeofedmonton = len(edmonton)
        self.assertAlmostEqual(sizeofedmonton, 3)

    def test_search_palauttaa_pelaajat(self):
        self.assertAlmostEqual(str(self.statistics.search("Kurri")),
                               "Kurri EDM 37 + 53 = 90")

    def test_search_palauttaa_None_jos_ei_pelaajaa_loydy(self):
        self.assertAlmostEqual(str(self.statistics.search("Mari")), "None")

    def test_sort_by_points_palauttaako(self):
        pistemiehet = self.statistics.top_scorers(4)
        self.assertAlmostEqual(str(pistemiehet[1]), "Lemieux PIT 45 + 54 = 99")
Beispiel #22
0
class BestAssetTest:
    def __init__(self, period):
        self.period = period
        self.statistics = Statistics(default="USDT")
        self.exchange = Exchange(default="USDT")
        self.current_asset_symbol = None

        self.buyPrice = 0

    def best_asset(self):
        try:
            ticker_range = ["BTC", "ETH", "NEO", "BNB", "LTC", "BCH"]
            best_asset_symbol = self.statistics.get_best_asset(
                self.period, ticker_range)

            if best_asset_symbol != self.current_asset_symbol:
                if self.current_asset_symbol is not None:
                    current_price = self.exchange.get_asset_price(
                        self.current_asset_symbol)

                    print(current_price)
                    percentage = (float(current_price) - float(
                        self.buyPrice)) / float(self.buyPrice) * 100
                    print(
                        "Selling asset %s at %s with percentage %s" %
                        (self.current_asset_symbol, current_price, percentage))

                    file_name = "output_%s.csv" % self.period.value
                    file = open(file_name, 'a')
                    try:
                        writer = csv.writer(file)
                        writer.writerow(
                            (self.current_asset_symbol, self.buyPrice,
                             current_price, percentage))
                    finally:
                        file.close()

                if best_asset_symbol is not None:
                    self.buyPrice = self.exchange.get_asset_price(
                        best_asset_symbol)
                    print("Buying asset %s at %s" %
                          (best_asset_symbol, self.buyPrice))

                # Set new current asset
                self.current_asset_symbol = best_asset_symbol
        except Exception as e:
            print(e)
            pass

    def run(self):
        print("[TEST] Strategy Best Asset %s" % self.period.value)
        while True:
            self.best_asset()
            time.sleep(10)  # Sleep 10 seconds
Beispiel #23
0
async def handle_1_TV_raffle(num, real_roomid, raffleid):
    # print('参与')
    await asyncio.sleep(random.uniform(0.5, min(30, num * 1.3)))
    json_response2 = await bilibili.get_gift_of_TV(real_roomid, raffleid)
    Printer().printlist_append(
        ['join_lottery', '小电视', 'user', f'参与了房间{real_roomid:^9}的小电视抽奖'], True)
    Printer().printlist_append([
        'join_lottery', '小电视', 'user', "# 小电视道具抽奖状态: ", json_response2['msg']
    ])
    # -400不存在
    # -500繁忙
    if not json_response2['code']:
        Statistics.append_to_TVlist(raffleid, real_roomid)
        return True
    elif json_response2['code'] == -500:
        print('# -500繁忙,稍后重试')
        return False
    else:
        print(json_response2)
        return True
Beispiel #24
0
    def __init__(self, dbName1, dbName2, rootDir = None):
        Statistics.__init__(self, dbName1, dbName2, rootDir)
        self.total = Statistics.numberOfGongLiNianEqual(self)
        self.rootDir = os.path.join(self.rootDir, u"步骤三数据库数据的匹配程度")
        if not os.path.exists(self.rootDir):
            os.mkdir(self.rootDir)
        
        self.rootDir = os.path.join(self.rootDir, u"2.不考虑公历年")    
        if not os.path.exists(self.rootDir):
            os.mkdir(self.rootDir)
        
        self.rootDir = os.path.join(self.rootDir, u"2.考虑季节")    
        if not os.path.exists(self.rootDir):
            os.mkdir(self.rootDir)
        
        self.rootDir = os.path.join(self.rootDir, u"ͬ3.连续2季")
        if not os.path.exists(self.rootDir):
            os.mkdir(self.rootDir)  

        self.logger = logging.getLogger('TwoJi')
Beispiel #25
0
    def DanMuraffle(self, dic):
        cmd = dic['cmd']
        if cmd == 'SPECIAL_GIFT':
            if 'data' in dic and '39' in dic['data'] and dic['data']['39'][
                    'action'] == 'start':
                printer.info([f'房间号{self.roomid}有节奏风暴'], True)
                rafflehandler.Rafflehandler.Put2Queue(
                    (self.target, self.roomid, dic['data']['39']['id']),
                    rafflehandler.handle_1_room_storm)
                Statistics.append2pushed_raffle('节奏风暴', 1)

        if cmd == 'GUARD_MSG':
            if 'buy_type' in dic and dic['buy_type'] != 1:
                # print(dic)
                printer.info([f'{self.area_id}号弹幕监控检测到{self.roomid:^9}的提督/舰长'],
                             True)
                rafflehandler.Rafflehandler.Put2Queue(
                    (self.target, self.roomid),
                    rafflehandler.handle_1_room_guard)
                Statistics.append2pushed_raffle('提督/舰长', area_id=self.area_id)
Beispiel #26
0
 def __init__(self, root):
     self.root = root
     self.root.title("Minesweeper")
     self.frame = Frame(root)
     self.frame.grid()
     self.size = (9,) * 2
     self.num_mines = 10
     self.stats = Statistics()
     self.buttons = {}
     self.add_menu_bar()
     self.add_header()
     self.new_game()
Beispiel #27
0
def main():

    Helper.init()

    totalTime = 0
    duration = args.duration
    if args.nosetup:
        itopod_setup = True
    else:
        itopod_setup = False
    while True:
        if not args.notitans:
            if args.verbose:
                print('getting available titans')
            titans = Adventure.getTitans()
            if titans:
                # after this needs to reset loadout and diggers and e/m
                Adventure.turnIdleOff()

                print('calling killTitans with args.snipe {args.snipe}')
                Adventure.killTitans(titans,
                                     verbose=args.verbose,
                                     snipe=args.snipe)

                itopod_setup = False

        if not itopod_setup:
            Setup.setup(args.setup)
            itopod_setup = True

        Navigation.menu('adventure')

        if not args.nobeast:
            if not Statistics.checkPixelColor(*coords.BEAST_MODE_ON,
                                              coords.BEAST_MODE_COLOR):
                Helper.click(*coords.BEAST_MODE)

        print('*' * 30)
        Itopod.itopodExperimental(duration=duration,
                                  optimal_floor=args.optimal)
        totalTime += duration
        print(f'total exp: {Itopod.EXP_gained}')
        print(f'total ap: {Itopod.AP_gained}')
        print(f'kills: {Itopod.kills}')
        print(f'total time: {totalTime} minutes')
        print('*' * 30)

        Navigation.menu('inventory')
        if Inventory.getEmptySlots() < 20:
            invManagement(boost=0, merge=0)

        if not args.noygg:
            Yggdrasil.harvestAll()
Beispiel #28
0
 def __init__(self, dbName1, dbName2, rootDir=None):
     Statistics.__init__(self, dbName1, dbName2, rootDir)
     self.total = self.table1.count()
     
     self.rootDir = os.path.join(self.rootDir, u"步骤三数据库数据的匹配程度")
     if not os.path.exists(self.rootDir):
         os.mkdir(self.rootDir)
     
     self.rootDir = os.path.join(self.rootDir, r"3.数据库1、2与数据库3的比对")    
     if not os.path.exists(self.rootDir):
         os.mkdir(self.rootDir)
     
     self.rootDir = os.path.join(self.rootDir, r"2.数据库2与数据库3对比")    
     if not os.path.exists(self.rootDir):
         os.mkdir(self.rootDir)
         
     self.logger = logging.getLogger('CompareDB2AndDB3')
     
     self.condition10to30 = self.extractData(-10, 30)
     self.condition20to40 = self.extractData(-20, 40)
     self.condition30to50 = self.extractData(-30, 50)
Beispiel #29
0
def main():
    parser = OptionParser()
    parser.add_option("-p",
                      "--db_path",
                      type="string",
                      help="Path to sqlite database with logs")
    opts, _ = parser.parse_args()

    if not opts.db_path:
        parser.error("Set the db path as argument")

    Statistics(opts.db_path).calculate_statistics()
 async def check_winner(self, i, g, start_time):
     # 开奖5s后检查是否中奖
     await asyncio.sleep(
         time.mktime(time.strptime(start_time, '%Y-%m-%d %H:%M:%S')) -
         time.time() + 5)
     response2 = await bilibili().get_winner_info(i, g)
     json_response2 = await response2.json(content_type=None)
     for winner in json_response2["data"]["winnerList"]:
         if winner["uid"] == bilibili().dic_bilibili['uid']:
             Printer().printer(f'实物抽奖中中奖: {winner["giftTitle"]}', "Lottery",
                               "cyan")
             Statistics().add_to_result(winner["giftTitle"], 1)
Beispiel #31
0
    def test_add_wrong_answer(self):
        """Проверка правильности работы статистики при добавлении неверного ответа"""
        # Получаем текущие значения количества верных и неверных ответов
        old_right_answers_count = Statistics(
            user_id=self.user_id).get_right_answers_count()
        old_wrong_answers_count = Statistics(
            user_id=self.user_id).get_wrong_answers_count()

        # Добавление в статистику неправильного ответа
        Statistics(user_id=self.user_id).add_wrong_answer()

        # Получение новых значений количества верных и неверных ответов
        new_right_answers_count = Statistics(
            user_id=self.user_id).get_right_answers_count()
        new_wrong_answers_count = Statistics(
            user_id=self.user_id).get_wrong_answers_count()

        # Количество верных ответов должно увеличиться на 1
        self.assertEqual(old_right_answers_count, new_right_answers_count)
        # Количество неверных ответов должно остаться неизменным
        self.assertEqual(old_wrong_answers_count + 1, new_wrong_answers_count)
Beispiel #32
0
def calculateErrorTypeI(scenarios, data, index, rejectAlpha):
    results = []
    for numberOfEvents in scenarios:
        statistics = runStudy(data, index, numberOfEvents)
        errorsTypeI = {
            statisticType: Statistics.errorTypeI(statistic, rejectAlpha,
                                                 statisticType)
            for statisticType, statistic in statistics.items()
        }
        results.append(errorsTypeI)

    return results
Beispiel #33
0
 def __init__(self, dbName1, dbName2, rootDir = None):
     Statistics.__init__(self, dbName1, dbName2, rootDir)
     #self.total = self.table1.find({'ji': {'$ne': ""}}).count()
     self.total = Statistics.numberOfGongLiNianEqual(self)
     self.rootDir = os.path.join(self.rootDir, u"步骤三数据库数据的匹配程度")
     if not os.path.exists(self.rootDir):
         os.mkdir(self.rootDir)
     
     self.rootDir = os.path.join(self.rootDir, u"2.不考虑公历年")    
     if not os.path.exists(self.rootDir):
         os.mkdir(self.rootDir)
     
     self.rootDir = os.path.join(self.rootDir, u"2.考虑季节")    
     if not os.path.exists(self.rootDir):
         os.mkdir(self.rootDir)
     
     self.rootDir = os.path.join(self.rootDir, u"ͬ4.连续3季")
     if not os.path.exists(self.rootDir):
         os.mkdir(self.rootDir)  
         
     self.logger = logging.getLogger('ThreeJi')
Beispiel #34
0
    def text(self):
        for name_text in self.__file_list:
            self.name_text = name_text
            print('Файл: ' + name_text)
            file = self.__path + name_text
            self.__encod = self.__encodingDefinition(file)
            with open(file, encoding=self.__encod) as text:
                self.__natural_text = text.read()
            if len(self.__natural_text) > 100:
                self.__natural_text = self.__tokenize(self.__natural_text)
                print('Длина текста: ' + str(len(self.__natural_text)))
                print('Длина словаря натурального текста: ' +
                      str(len(self.__natural_dictionary)))
                print(self.__natural_dictionary)
                print('Длина словаря сгенерированного текста: ' +
                      str(len(self.__generated_dictionary)))
                print(self.__generated_dictionary)

                graph = Graph.createGraph(self.__natural_dictionary,
                                          self.__natural_text)
                natural_statistics = Statistics(graph,
                                                len(self.__natural_text))
                graph = []

                graph = Graph.createGraph(self.__generated_dictionary,
                                          self.__generated_text)
                gen_statistics = Statistics(graph, len(self.__generated_text))
                graph = []

                self.plot.statisticsComp(natural_statistics, gen_statistics)

                self.__generated_text = []
                self.__natural_dictionary = []
                self.__generated_dictionary = []

        self.plot.createPlots()
        self.plot.createPlotsAV()
        self.plot.createPlotsSTD()
        self.plot.createPlotsSTDmean()
        self.plot = BuildPlot(len(self.__file_list))
Beispiel #35
0
    def get(self):
        statistics = Statistics(Utils.general_stats_cache_path)

        x = statistics.readCachedStatistics()
        if x != '':
            return json.loads(x)

        csv_file = open(Utils.train_file_path, "r")
        csv_reader = csv.reader(csv_file, delimiter=',')
        first = True
        data = Model_Statistics()
        for row in csv_reader:
            if first == True:
                first = False
                continue
            data.push(row[0], row[1], row[2], row[3], row[4], row[5], row[6],
                      row[7], row[8], row[9])

        dataDictionary = data.getArrayForKeys()
        del dataDictionary['dataCount']
        dataDictionaryKeys = dataDictionary.keys()

        response = jsonify(
            statistics.buildDictionaryStats(dataDictionary,
                                            dataDictionaryKeys))
        statistics.writeStatisticsCache(response.get_data(as_text=True))
        return response
Beispiel #36
0
class RestaurantDataTestCase(unittest.TestCase):
    connection_string = "host='localhost' dbname='motordb' user='******' password='******'"

    conn = psycopg2.connect(connection_string)

    def setUp(self):
        with self.conn.cursor() as cursor:
            setup_queries = open('load_data.sql', 'r').read()
            cursor.execute(setup_queries)
            self.conn.commit()

        self.service = lookupdata(self.connection_string)
        self.service = Statistics(self.connection_string)

    def tearDown(self):
        self.service = None

    def query(self, query, parameters=()):
        cursor = self.conn.cursor()
        cursor.execute(query, parameters)
        return cursor.fetchall()

    def test_connectivity(self):
        self.assertEqual(True, self.service.check_connectivity())

    def test_find_recipe(self):
        recipes = self.service.find_recipe('ham')
        self.assertEqual(len(recipes), 3)
        self.assertTrue(
            list(map(lambda r: r['name'], recipes)).index('Hamburger') >= 0)

        recipes = self.service.find_recipe('sandwich')
        self.assertEqual(len(recipes), 2)

        recipes = self.service.find_recipe(
            "';DROP TABLE recipe_ingredient;COMMIT;")
        self.assertEqual(len(recipes), 0)
        self.assertEqual(
            22,
            self.query("select count(*) from recipe_ingredient")[0][0])
Beispiel #37
0
    def handle_danmu(self, body):
        dic = json.loads(body.decode('utf-8'))
        cmd = dic['cmd']

        if cmd == 'PREPARING':
            printer.info([f'{self._area_id}号弹幕监控房间下播({self._room_id})'], True)
            return False

        elif cmd == 'NOTICE_MSG':
            # 1 《第五人格》哔哩哔哩直播预选赛六强诞生!
            # 2 全区广播:<%user_name%>送给<%user_name%>1个嗨翻全城,快来抽奖吧
            # 3 <%user_name%> 在 <%user_name%> 的房间开通了总督并触发了抽奖,点击前往TA的房间去抽奖吧
            # 4 欢迎 <%总督 user_name%> 登船
            # 5 恭喜 <%user_name%> 获得大奖 <%23333x银瓜子%>, 感谢 <%user_name%> 的赠送
            # 6 <%user_name%> 在直播间 <%529%> 使用了 <%20%> 倍节奏风暴,大家快去跟风领取奖励吧!(只报20的)
            # 8 全区广播:主播<%红莉栖魔王喵%>开启了“任意门”,点击前往TA的房间去抽奖吧!
            msg_type = dic['msg_type']
            msg_common = dic['msg_common']
            real_roomid = dic['real_roomid']
            msg_common = dic['msg_common'].replace(' ', '')
            msg_common = msg_common.replace('”', '')
            msg_common = msg_common.replace('“', '')
            if msg_type == 2 or msg_type == 8:
                str_gift = msg_common.split('%>')[-1].split(',')[0]
                if '个' in str_gift:
                    raffle_num, raffle_name = str_gift.split('个')
                elif '了' in str_gift:
                    raffle_num = 1
                    raffle_name = str_gift.split('了')[-1]
                else:
                    raffle_num = 1
                    raffle_name = str_gift
                broadcast = msg_common.split('广播')[0]
                printer.info(
                    [f'{self._area_id}号弹幕监控检测到{real_roomid:^9}的{raffle_name}'],
                    True)
                rafflehandler.Rafflehandler.Put2Queue(
                    (real_roomid, ), rafflehandler.handle_1_room_TV)
                broadcast_type = 0 if broadcast == '全区' else 1
                Statistics.add2pushed_raffle(raffle_name, broadcast_type)
            elif msg_type == 3:
                raffle_name = msg_common.split('开通了')[-1][:2]
                printer.info(
                    [f'{self._area_id}号弹幕监控检测到{real_roomid:^9}的{raffle_name}'],
                    True)
                rafflehandler.Rafflehandler.Put2Queue(
                    (real_roomid, ), rafflehandler.handle_1_room_guard)
                broadcast_type = 0 if raffle_name == '总督' else 2
                Statistics.add2pushed_raffle(raffle_name, broadcast_type)
            elif msg_type == 6:
                raffle_name = '二十倍节奏风暴'
                printer.info(
                    [f'{self._area_id}号弹幕监控检测到{real_roomid:^9}的{raffle_name}'],
                    True)
                rafflehandler.Rafflehandler.Put2Queue(
                    (real_roomid, ), rafflehandler.handle_1_room_storm)
                Statistics.add2pushed_raffle(raffle_name)

        return True
Beispiel #38
0
def main():
    current_path = os.path.dirname(os.path.abspath(__file__))
    os.chdir(current_path)
    dirs, xlsx_files = find_excel()
    xlsx_files = exclude_done(dirs, xlsx_files)

    if len(xlsx_files) == 0:
        print('XLSX FILE NOT FOUND OR ALREADY DONE')
        exit()
    else:
        # length = len(xlsx_files)
        # threads = [None] * length
        # for i in range(0, length):
        #     statistics = Statistics()
        #     threads[i] = Thread(target=statistics.count(),
        #                         args=[xlsx_files[i]])
        #     threads[i].start()
        for xlsx_file in xlsx_files:
            statistics = Statistics()
            os.chdir(current_path)
            statistics.count(xlsx_file)
            print('STATISTICS DONE: {}'.format(os.path.splitext(xlsx_file)[0]))
async def handle_1_TV_raffle(num, real_roomid, raffleid):
    #print('参与')
    await asyncio.sleep(random.uniform(1, min(30, num * 1.5)))
    response2 = await bilibili().get_gift_of_TV(real_roomid, raffleid)
    Printer().printlist_append(['join_lottery', '小电视', 'user', "参与了房间{:^9}的小电视抽奖".format(real_roomid)], True)
    json_response2 = await response2.json()
    Printer().printlist_append(
        ['join_lottery', '小电视', 'user', "# 小电视道具抽奖状态: ", json_response2['msg']])
    # -400不存在
    if json_response2['code'] == 0:
        Statistics().append_to_TVlist(raffleid, real_roomid)
    else:
        print(json_response2)
Beispiel #40
0
    def __init__(self, dbName1, dbName2, year, rootDir = None):
        Statistics.__init__(self, dbName1, dbName2, rootDir)
        self.total = self.table1.find({'ji': {'$ne': ""}}).count()
        
        rootDir = os.path.join(os.path.dirname(__file__), u"数据库1_1")

        if not os.path.exists(rootDir):
            os.mkdir(rootDir)    
        if year < 0:
            rootDir = os.path.join(rootDir, "提前{}year".format(abs(year)))
        elif year > 0:
            rootDir = os.path.join(rootDir, "延后{}year".format(abs(year)))
        else:
            rootDir = os.path.join(rootDir, "同一年year")
        if not os.path.exists(rootDir):
            os.mkdir(rootDir)    
        self.rootDir = rootDir
        
        self.year = year
            
        self.logger = logging.getLogger('Statistics1_1')
        self.logger.info("totol record: {}".format(self.total))
Beispiel #41
0
 def __init__(self, dbName1, dbName2, rootDir = None):
     Statistics.__init__(self, dbName1, dbName2, rootDir)
     self.total = self.table1.find({'ji': {'$ne': ""}}).count()
     #self.total = Statistics.numberOfGongLiNianEqual(self)
     self.rootDir = os.path.join(self.rootDir, u"步骤三数据库数据的匹配程度")
     if not os.path.exists(self.rootDir):
         os.mkdir(self.rootDir)
     
     self.rootDir = os.path.join(self.rootDir, u"2.不考虑公历年")    
     if not os.path.exists(self.rootDir):
         os.mkdir(self.rootDir)
     
     self.rootDir = os.path.join(self.rootDir, u"3.考虑公历年")    
     if not os.path.exists(self.rootDir):
         os.mkdir(self.rootDir)
     
     self.rootDir = os.path.join(self.rootDir, u"4.连续4年+3") 
     if not os.path.exists(self.rootDir):
         os.mkdir(self.rootDir)    
         
     self.logger = logging.getLogger('TwoYear')
     self.logger.info("totol record: {}".format(self.total))
 def enabled_stats(self):
     """Return all enabled statistics as a list of string names."""
     if not self.enabled_statistics:
         json_enabled_stats_dict = self.config.get(
             'enabled_stats',
             {stat_name: True
              for stat_name in list(Statistics)})
         self.enabled_statistics = [
             Statistics.from_string(stat_name)
             for stat_name, stat_enabled in json_enabled_stats_dict.items()
             if stat_enabled
         ]
     return self.enabled_statistics
    def getExamStatistics(self, attemp=0):
        sample = []
        for userid, g in groupby(self.track.values(), key=lambda r: r.userName):
            ## !!!! check if have more than one for filter the attemp
            data = sorted(g, key=lambda x: x.timeStamp)[attemp] # filter the attemp

            if data.data['evaluation.scored']:
                sample.append(data.data['evaluation.score'])

        if not sample:
            sample = [0]
            
        return Statistics(sample)
Beispiel #44
0
def test_simulation_run():
    print("### test_simulation_run() ###")
    universe = Universe(2, 5, 0.4, debug=True)
    stats = Statistics()
    print("Start:")
    print_environment(universe)
    print("Agent stats:")
    for agent in universe.agents:
        agent.print_stats()

    while not universe.is_finished():
        universe.update(stats)
        print_environment(universe)
Beispiel #45
0
class Comparer:
    """
    Class compares two playlists and contains information about their comparison
    Relevant Instance Variables defined in __init__ :
        playlist1 = playlist of user 1
        playlist2 = playlist of user 2
        comparison = tuple (sharedSongs, sharedArtists, artistsCount) of type (Playlist, Set, Int)
                        see playlist.compare() for more info
        similarity = similarity score for playlist1 and playlist2 of type float
    """
    def __init__(self, playlist1, playlist2):
        self.playlist1 = playlist1
        self.playlist2 = playlist2
        self.comparison = playlist1.compare(playlist2)
        self.calculator = Statistics()
        self.similarity = self.setSimilarity()

    def printCommonSongs(self):
        """Prints songs shared between both profiles"""
        print(self.comparison[0])

    def setSimilarity(self):
        """should not be used outside class, instead access Comparer.similarity"""
        plen1 = len(self.playlist1.songs)
        plen2 = len(self.playlist2.songs)
        sharedlen = len(self.comparison[0].songs)
        artistslen = self.comparison[2]
        similarity = self.calculator.similarityMetric(plen1, plen2, sharedlen,
                                                      artistslen)
        return similarity

    def isSimilar(self, minSimilarity):
        return self.similarity >= minSimilarity

    def getMissingSongs(self, profile=0):
        """Returns: playlist with songs in playlist2 and not in playlist1 if param==0, songs in playlist1 not in playlist2 else"""
        if profile == 0:
            missingSongs = Playlist("missing from User 1", [])
            for song in self.playlist2.songs:
                if song in self.playlist1.songs:
                    continue
                missingSongs.add(song)
            return missingSongs

        missingSongs = Playlist("missing from User 2", [])
        for song in self.playlist1.songs:
            if song in self.playlist2.songs:
                continue
            missingSongs.add(song)
        return missingSongs
Beispiel #46
0
async def handle_1_TV_raffle(type, num, real_roomid, raffleid):
    await asyncio.sleep(random.uniform(0.5, min(10, num * 1)))
    response2 = await bilibili().get_gift_of_TV(type, real_roomid, raffleid)
    Printer().printlist_append([
        'join_lottery', '广播道具', 'user', "参与了房间{:^9}的广播抽奖".format(real_roomid)
    ], True)
    json_response2 = await response2.json()
    Printer().printlist_append(
        ['join_lottery', '广播道具', 'user', "广播道具抽奖状态: ", json_response2['msg']],
        True)
    if json_response2['code'] == 0:
        Statistics().append_to_TVlist(raffleid, real_roomid)
    else:
        print(json_response2)
Beispiel #47
0
    def __init__(self):
        self.friendly_prob = 0.25
        self.sim_speed = 0
        self.init = 1
        self.turretCounter = 0
        self.planeCounter = 0
        self.clear_messages_counter = 10  #Clears all messages when planeCounter exceeds this threshold
        self.sim_stop = 100  #Number of resets of simulation
        self.numPlanes = 1
        self.numTurrets = 3
        self.turret_range = 4

        self.model = Model()
        self.model.turret_enemy_threshold = 1  #Number of turrets that need to identify a plane as enemy before any of the turrets start to shoot
        self.statistics = Statistics(self.model)
        # self.demospeed = SPEED
        self.paused = True
        self.step = False
        self.running = True
        self.show_statistics = False
        self.get_kb = False
        self.show_messages = False
        self.simulation = 0
class TestStatistics(unittest.TestCase):
    def setUp(self):
        # annetaan Statistics-luokan oliolle "stub"-luokan olio
        self.statistics = Statistics(PlayerReaderStub())

    def test_top_scorers_one(self):
        topscorer = self.statistics.top_scorers(0)
        self.assertEqual(len(topscorer), 1)
        self.assertEqual(topscorer[0].name, "Gretzky")

    def test_team_players(self):
        teamplayers = self.statistics.team("PIT")
        self.assertEqual(len(teamplayers), 1)
        self.assertEqual(teamplayers[0].name, "Lemieux")

    def test_search(self):
        result = self.statistics.search("Kurri")
        self.assertEqual(result.name, "Kurri")
        self.assertEqual(result.team, "EDM")

    def test_search_notfound(self):
        result = self.statistics.search("Nobody")
        self.assertIsNone(result)
Beispiel #49
0
async def get_results(message: types.Message):
    r = Statistics(db).get_statistics()[:3]
    message_text = "Congratulations to today's winners:\n"
    prizes = ['🥇', '🥈', '🥉']
    counter = 1
    db.reset()

    for i in r:
        message_text += f"{prizes[counter - 1]} - <b>{i.username}</b>\n"
        i.rank = prizes[counter - 1]
        db.update(i)
        counter += 1

    await message.reply(message_text, parse_mode='html')
Beispiel #50
0
async def handle_1_TV_raffle(type, raffleid, time_wait, time_limit, num,
                             real_roomid):
    Statistics().append_to_TVlist(raffleid, time_limit)
    await asyncio.sleep(
        min(
            max(0, time_wait) + random.uniform(0, min(num, 30)),
            time_limit - 1))
    response2 = await bilibili().get_gift_of_TV(type, real_roomid, raffleid)
    # Printer().printer(f"参与了房间 {real_roomid} 的广播抽奖 {raffleid}", "Lottery", "cyan")
    json_response2 = await response2.json(content_type=None)
    # Printer().printer(f"参与房间 {real_roomid} 广播道具抽奖 {raffleid} 状态: {json_response2['msg']}", "Lottery", "cyan")
    if json_response2['code'] == 0:
        data = json_response2["data"]
        Printer().printer(
            f"房间 {real_roomid} 广播道具抽奖 {raffleid} 结果: {data['award_name']}X{data['award_num']}",
            "Lottery", "cyan")
        Statistics().add_to_result(data['award_name'], int(data['award_num']))
    else:
        # {"code":-403,"data":null,"message":"访问被拒绝","msg":"访问被拒绝"}
        Printer().printer(
            f"房间 {real_roomid} 广播道具抽奖 {raffleid} 结果: {json_response2['message']}",
            "Lottery", "cyan")
        print(json_response2)
Beispiel #51
0
async def handle_1_activity_raffle(num, giftId, text1, text2, raffleid):
    #print('参与')
    await asyncio.sleep(random.uniform(1, min(30, num * 1.5)))
    response1 = await bilibili().get_gift_of_events_app(text1, text2, raffleid)
    pc_response = await bilibili().get_gift_of_events_web(
        text1, text2, raffleid)

    Printer().printlist_append([
        'join_lottery', '', 'user', "参与了房间{:^9}的{}活动抽奖".format(
            text1,
            bilibili().get_giftids_raffle(str(giftId)))
    ], True)

    json_response1 = await response1.json()
    json_pc_response = await pc_response.json()
    if json_response1['code'] == 0:
        Printer().printlist_append([
            'join_lottery', '', 'user', "# 移动端活动抽奖结果: ",
            json_response1['data']['gift_desc']
        ])
        Statistics().add_to_result(
            *(json_response1['data']['gift_desc'].split('X')))
    else:
        print(json_response1)
        Printer().printlist_append([
            'join_lottery', '', 'user', "# 移动端活动抽奖结果: ",
            json_response1['message']
        ])

    Printer().printlist_append([
        'join_lottery', '', 'user', "# 网页端活动抽奖状态: ",
        json_pc_response['message']
    ])
    if json_pc_response['code'] == 0:
        Statistics().append_to_activitylist(raffleid, text1)
    else:
        print(json_pc_response)
Beispiel #52
0
 def allocate_degrees(self):
     """
     First sort banks by asset size, then match them with sorted degree list.
     Node degrees are governed by a power law.
     :rtype : None
     """
     self.banks.sort(key=lambda _bank: _bank.balance.assets)
     degrees = [math.floor(Statistics.draw_from_powerlaw(POWERLAW_EXPONENT_OUT_DEGREE, 1.0) + 0.6748)
                for degree in xrange(0, len(self.banks))]
     for i in xrange(0, len(degrees)):
         if degrees[i] > MAX_K_OUT:
             degrees[i] = MAX_K_OUT
     degrees.sort()
     for n in xrange(0, len(self.banks)):
         self.banks[n].out_degree = degrees[n]
	def __init__(self):

		font = sf.Font.from_file("media/fonts/UbuntuMono-R.ttf")
		self.statistics = Statistics(font)

		window_settings = sf.window.ContextSettings()
		window_settings.antialiasing_level = 8
		self.window = sf.RenderWindow(
			sf.VideoMode(width, height),
			"Steering Behaviors For Autonomous Characters",
			sf.Style.DEFAULT, window_settings)
		self.window.vertical_synchronization = False

		self.entities = []
		self.grid = CollisionGrid(width, height, cell_size)
		self.collision = 0
    def __init__(self, samplesFile, batchSize, binSize, stdDevThreshold, windowSize, recurrentThreshold):
        CFGBuilder.__init__(self)

        self.stat = Statistics(binSize, stdDevThreshold)
        self.ifb = InputFileBuffer(50000, samplesFile)
        self.batchSize = batchSize
        self.binSize = binSize
        self.stdDevThreshold = stdDevThreshold
        self.samplesFile = samplesFile
        self.windowSize = windowSize
        self.recurrentThreshold = recurrentThreshold
        self.targets = dict()
        self.bbr = BBRepository()
        self.cfg = CFG()
        self.numMerge = 0
        self.highStdevEdges = 0
        self.numHighStdevTries = 0
        self.numHighStdevOK = 0
Beispiel #55
0
 def get(self):
     ip = self.request.remote_addr
     user = users.get_current_user()
     if not user or not users.is_current_user_admin():
         self.redirect(users.create_login_url(self.request.uri))
     template_values = {'user': user,}
     sta = Statistics.all()
     sta.order("-mtime")
     uids = []
     for s in sta.fetch(100):
         if not s.addr:
             s.addr = addr.ip2addr(s.ip)
             s.put()
         uids.append({'uid':s.uid,'ip':s.ip,'mtime':s.mtime+datetime.timedelta(hours=8),
             'url':s.url,'user_agent':s.user_agent,'addr':s.addr})
     template_values.update({'statistics':uids})
     template = JINJA_ENVIRONMENT.get_template('admin.html')
     self.response.write(template.render(template_values))
Beispiel #56
0
    def __init__(self, window, population, maze, stats_height=160, **kwagrs):
        # TODO ability to handle hiding statistics
        super(ExperimentMode, self).__init__()
        self.paused = False
        self.window = window
        self.width = window.width
        self.height = window.height
        self.groups = BatchGroup()

        grid_size = (self.height-stats_height) // GRID_SCALE, self.width // GRID_SCALE
        maze = maze if maze is not None else Walls(grid_size)
        env = Environment(maze, GRID_SCALE, FOOD_INIT_PROB)
        env.set_stats(Statistics.for_shape(self.width))
        env.set_population(population)
        # split window
        self.env_view = EnvironmentView(env, self.width, self.height-stats_height, **kwagrs)
        self.stats_view = StatsView(env.stats, 0, self.height-stats_height,
                                    self.width, stats_height, **kwagrs)
        self.groups.add_objects([self.env_view, self.stats_view])
Beispiel #57
0
 def step1(self):
     resultDir = self.createDir(str(1))
     (match, no_match) = self.createResultFile(resultDir)
 
     success = 0
     failed  = 0    
     for element in self.table1.find({'ji': {'$ne': ""}}):
         res = self.table2.find_one({'guanZhi' : element['guanZhi'],
                                  'gongLiNian' : element['gongLiNian'],
                                     'name'    :  element['name']})
         if res and (len(res['ji']) > 0) and (Statistics.convertJi(self, res['ji']) == int(element['ji'])):
             match.write(self.formatElement(element))
             success += 1
         else:
             no_match.write(self.formatElement(element))
             failed += 1
     failed = self.total - success
     result = (success, success/self.total, failed, failed/self.total)    
     self.logResult(1, result) 
     return result
    def __init__(self, auto_mode=False, send_email=False, skip_compilation=False):
        build_dir = get_build_dir()

        self.bb = Bitbake(build_dir)

        try:
            self.base_env = self.bb.env()
        except EmptyEnvError as e:
            import traceback
            E( " %s\n%s" % (e.message, traceback.format_exc()))
            E( " Bitbake output:\n%s" % (e.stdout))
            exit(1)

        self._set_options(auto_mode, send_email, skip_compilation)

        self._make_dirs(build_dir)

        self._add_file_logger()

        self.email_handler = Email(settings)
        self.statistics = Statistics()
Beispiel #59
0
    def __init__(self, clients, games, authManager, reactor):
        self.id = Client.nextId
        Client.nextId += 1

        self.logger = logging.getLogger("client-%d" % self.id)
        self.logger.info("client initialized")

        self.clients = clients
        self.games = games
        self.authManager = authManager
        self.reactor = reactor

        # not yet logged in
        self.loggedIn = False
        self.name = None

        # no own game yet
        self.game = None

        # not ready to start yet
        self.readyToStart = False

        # no UDP handler yet connected to the client
        self.udpHandler = None

        # statistics
        self.statistics = Statistics()

        # set up the handlers
        self.handlers = {
            TcpPacket.LOGIN: self.handleLogin,
            TcpPacket.ANNOUNCE: self.handleAnnounce,
            TcpPacket.LEAVE_GAME: self.handleLeave,
            TcpPacket.JOIN_GAME: self.handleJoin,
            TcpPacket.DATA: self.handleData,
            TcpPacket.READY_TO_START: self.handleReadyToStart,
            TcpPacket.GET_RESOURCE_PACKET: self.handleGetResource,
            TcpPacket.KEEP_ALIVE_PACKET: self.handleKeepAlivePacket,
        }
 def initialize(self):
     self.verbose = True
     self.statistics = Statistics()
     self.statistics.initialize(self)
     self.knowledge = Knowledge()
     self.knowledge.initialize(self)
     
     #todo: make this more generic,
     # i.e. allow for an arbitrary number of roles
     # load all rule bases
     self.loadMetaRules()
     self.loadAttackerRules()
     self.loadDefenderRules()
     self.loadCatcherRules()
     
     # distribute the roles to the bots 
     roleList = self.metaScript.runDynamicScript([len(self.game.team.members),self.statistics])
     if(roleList != None):
         self.distributeRoles(roleList)
     else: #If none of the rules apply, use a mixed team.
         self.distributeRoles(metaRules.mixedAttackers(len(self.game.team.members)))
     # and generate the corresponding scripts
     self.initializeRoles()
     self.initializeBotStats()