def update_statistic(): current_game = CurrentGame.query.all() for game in current_game: statistic_entry = Statistic(user_id=game.user_id) statistic_entry.game_type = game.game_type statistic_entry.total_rounds = game.total_rounds statistic_entry.correct_answers = game.correct_answers db.session.add(statistic_entry) db.session.delete(game) db.session.commit() return {'result': 'success'}
def game_statistic(): revision_game_entry = CurrentGame.query.filter_by( user_id=current_user.id, game_completed=True).first() total_rounds = revision_game_entry.total_rounds correct_answers = revision_game_entry.correct_answers # Update statistic table statistic_entry = Statistic(user_id=current_user.id) statistic_entry.game_type = revision_game_entry.game_type statistic_entry.total_rounds = total_rounds statistic_entry.correct_answers = correct_answers db.session.add(statistic_entry) db.session.delete(revision_game_entry) db.session.commit() return render_template('games/game_statistic.html', total_rounds=total_rounds, correct_answers=correct_answers)
def schedulerdeletegame(): # print(todayDate) todayDate = datetime.now() print(todayDate) delta = relativedelta(days=-1) one_hour = todayDate + delta # delta = relativedelta(minute=+10) # one_hour = todayDate - delta print(one_hour) old_games = Game.query.filter(Game.refreshed <= one_hour).all() # noqa for old_game in old_games: print('old_game.refreshed:{}'.format(old_game.refreshed)) print('delte: {}'.format(old_game)) stat = Statistic() stat.usercount = len(old_game.users) stat.started = old_game.started stat.refreshed = old_game.refreshed stat.halfcount = old_game.halfcount db.session.add(stat) db.session.commit() for user in old_game.users: db.session.delete(user) db.session.commit() db.session.delete(old_game) db.session.commit() db.session.commit()
def statistic(): """ Return statistic for current game. Add entry to Statistic Delete current game """ db_user = User.check_request(request) revision_game_entry = CurrentGame.query.\ filter_by(user_id=db_user.id).first() if revision_game_entry is None: revision_game_entry = CurrentGame.query.\ filter_by(user_id=db_user.id).first() if revision_game_entry is None: return {'redirect': '/games'} else: return {'redirect': '/play'} total_rounds = revision_game_entry.total_rounds correct_answers = revision_game_entry.correct_answers # Update statistic table statistic_entry = Statistic(user_id=db_user.id) statistic_entry.game_type = revision_game_entry.game_type statistic_entry.total_rounds = total_rounds statistic_entry.correct_answers = correct_answers if db_user and db_user.is_authenticated(): db.session.add(statistic_entry) db.session.delete(revision_game_entry) db.session.commit() return { 'total_rounds': total_rounds, 'correct_answers': correct_answers, 'game_type': GameType[revision_game_entry.game_type].value }
def increase_comment(): today_statistic = Statistic.query.filter_by(date=s_today()).first() if today_statistic: today_statistic.increase_comment() else: # 如果没有今天的统计数据则新建 yesterday_statistic = Statistic.query.filter_by( date=s_yesterday()).first() new_statistic = Statistic() new_statistic.from_yesterday_statistic(yesterday_statistic) new_statistic.increase_comment() db.session.add(new_statistic) db.session.commit() return jsonify({'success': 'total_comment & new_comment + 1'})
def statistic(): todayDate = datetime.now() delta = relativedelta(days=-1) one_day = todayDate + delta print('Schedular runs') try: old_games = db.session.query(Game).filter( Game.refreshed <= one_day).with_for_update().all() if len(old_games) > 0: for old_game in old_games: stat = Statistic() stat.usercount = len(old_game.users) stat.started = old_game.started stat.refreshed = old_game.refreshed stat.halfcount = old_game.halfcount stat.schockoutcount = old_game.schockoutcount stat.fallling_dice_count = old_game.fallling_dice_count stat.changs_of_fallling_dice = old_game.changs_of_fallling_dice stat.throw_dice_count = old_game.throw_dice_count stat.stack_max = old_game.stack_max stat.play_final = old_game.play_final stat.finalcount = old_game.finalcount db.session.add(stat) for user in old_game.users: db.session.delete(user) db.session.delete(old_game) db.session.commit() finally: db.session.commit()
def convert_file_dxf(): if 'username' not in session: user_logout() post = False form = request.form.to_dict() layers = [] cad_version = '' # Load possible file errors errors, duplicate_color_errors, \ cad_color_errors = check_files_errors(get_config_file(), post) if not errors: layers = get_layers_table() elif (get_errors_upload_topographical_file() or file_empty( os.path.join(session['files_folder'], session['topographical_file'])) or errors_square() or errors_rectangle()) \ or (session['config_file'] and ( get_errors_config_file() or file_empty(os.path.join(session['files_folder'], session['config_file'])) or get_errors_config_file_duplicate_elements())) \ or (session['symbols_file'] and error_symbols()): shutil.rmtree(session['files_folder']) if request.method == "POST": post = True cad_version = form['cadversion'] del form['cadversion'] session['dxf_filename'] = form['dxf_filename'] del form['dxf_filename'] # Check if the file extension is correct (dxf) check_DXF_ext() # Updating the layers layers.clear() layers = update_layers(form) # Load possible file errors errors, duplicate_color_errors, \ cad_color_errors = check_files_errors(get_dxf_configuration(layers), post) if duplicate_color_errors or cad_color_errors: return render_template( 'convert.html', title='Conversion DXF', form=form, layers=layers, dxf_filename=session['dxf_filename'], cad_version=cad_version, symbols=get_symbols(), cad_versions=app.config["CAD_VERSIONS"], errors=errors, duplicate_color_errors=duplicate_color_errors, cad_color_errors=cad_color_errors) # Generate the DXF and add it to the list of user generated in the session converted = generate_dxf(session['files_folder'], session['dxf_filename'], layers, cad_version) if converted: session['converted_files'].append({ 'folder': session['files_folder'], 'file': session['dxf_filename'] }) # Accounting of files converted by the user statistic_query = Statistic.query.filter_by( username_id=session['id'], id=date.today()).first() if statistic_query is None: st = Statistic(id=date.today(), username_id=session['id']) db.session.add(st) st.file_converts = 1 else: statistic_query.file_converts = statistic_query.file_converts + 1 db.session.add(statistic_query) db.session.commit() flash('File successfully converted!!!') else: flash('Error: File could not be generated!!!') return redirect(url_for("downloads")) return render_template('convert.html', title='Conversion DXF', form=form, layers=layers, dxf_filename=session['dxf_filename'], cad_version=cad_version, symbols=get_symbols(), cad_versions=app.config["CAD_VERSIONS"], errors=errors, duplicate_color_errors=duplicate_color_errors, cad_color_errors=cad_color_errors)
def deploy(): """ run deployment tasks """ # 1. 创建角色 Role.insert_roles() # 2. 初始化统计数据 Statistic.init_statistic()
def seed_statistic(): "Create RoseGuarden database filled with testdata for the statistics" Statistic.query.delete() StatisticEntry.query.delete() userCountStat = Statistic("User total", StatisticsManager.STATISTICS_STATID_USERCOUNT, Statistic.STATTYPE_LINE_SERIES, 0, 3, "", 0, "Users", "Admins", "Supervisors") accessesStat = Statistic("Accesses total", StatisticsManager.STATISTICS_STATID_ACCESSES, Statistic.STATTYPE_LINE_SERIES, 0, 2, "", 0, "Card auth.", "Web auth.") weekdayStat = Statistic("Accesses per weekday", StatisticsManager.STATISTICS_STATID_WEEKDAYS, Statistic.STATTYPE_RADAR_SERIES, 7, 1, "", 0, "Weekdays") doorStat = Statistic("Accesses per node", StatisticsManager.STATISTICS_STATID_NODE_ACCESSES, Statistic.STATTYPE_DOUGHNUT_CLASSES, 2, 0, "", 0) loginsCountStat = Statistic("Logins", StatisticsManager.STATISTICS_STATID_LOGINS, Statistic.STATTYPE_LINE_SERIES, 0, 2, "", 0, "Logins", "Failed attempts") secuirityStat = Statistic("Security warnings", StatisticsManager.STATISTICS_STATID_SECURITY, Statistic.STATTYPE_LINE_SERIES, 0, 3, "", 0, "Failed login", "Failed API auth.", "Worker errors") activityGroupsStat = Statistic( "User activity groups", StatisticsManager.STATISTICS_STATID_ACTIVITY_USER_GROUPS, Statistic.STATTYPE_YEARLY_BAR_SERIES, 0, 4, "", Statistic.STATDISPLAY_CONFIG_NO_TOTAL, "Zero activity users", "Low activity users", "Medium activity users", "High activity users") activityAccessesStat = Statistic( "Average accesses of user groups", StatisticsManager.STATISTICS_STATID_USER_GROUPS_ACCESSES, Statistic.STATTYPE_LINE_SERIES, 0, 3, "", Statistic.STATDISPLAY_CONFIG_NO_TOTAL, "Low activity users", "Medium activity users", "High activity users") activityAverageStat = Statistic( "Total accesses of user groups", StatisticsManager.STATISTICS_STATID_USER_GROUPS_AVERAGE, Statistic.STATTYPE_YEARLY_BAR_SERIES, 0, 3, "", Statistic.STATDISPLAY_CONFIG_NO_TOTAL, "Low activity users", "Medium activity users", "High activity users") db.session.add(userCountStat) db.session.add(accessesStat) db.session.add(activityGroupsStat) db.session.add(activityAccessesStat) db.session.add(activityAverageStat) db.session.add(doorStat) db.session.add(loginsCountStat) db.session.add(weekdayStat) db.session.add(secuirityStat) # add entry for usercount for year in range(2015, 2017): for month in range(1, 13): if year >= datetime.datetime.now().year: if month > datetime.datetime.now().month: break # STATISTICS_STATID_ACTIVITY_USER_GROUPS entries db.session.add( StatisticEntry( StatisticsManager.STATISTICS_STATID_ACTIVITY_USER_GROUPS, str(month) + "/" + str(year % 1000), random.randrange(20, 120), StatisticsManager.SERIES_GROUPS_NO_ACTIVITY, month, year, StatisticsManager.BINNING_NONE)) db.session.add( StatisticEntry( StatisticsManager.STATISTICS_STATID_ACTIVITY_USER_GROUPS, str(month) + "/" + str(year % 1000), random.randrange(5, 15), StatisticsManager.SERIES_GROUPS_LOW_ACTIVITY, month, year, StatisticsManager.BINNING_NONE)) db.session.add( StatisticEntry( StatisticsManager.STATISTICS_STATID_ACTIVITY_USER_GROUPS, str(month) + "/" + str(year % 1000), random.randrange(2, 6), StatisticsManager.SERIES_GROUPS_MEDIUM_ACTIVITY, month, year, StatisticsManager.BINNING_NONE)) db.session.add( StatisticEntry( StatisticsManager.STATISTICS_STATID_ACTIVITY_USER_GROUPS, str(month) + "/" + str(year % 1000), random.randrange(2, 6), StatisticsManager.SERIES_GROUPS_HIGH_ACTIVITY, month, year, StatisticsManager.BINNING_NONE)) # STATISTICS_STATID_USER_GROUPS_ACCESSES entries db.session.add( StatisticEntry( StatisticsManager.STATISTICS_STATID_USER_GROUPS_ACCESSES, str(month) + "/" + str(year % 1000), random.randrange(20, 120), StatisticsManager.SERIES_GROUP_BY_LOW_ACTIVITY, month, year, StatisticsManager.BINNING_NONE)) db.session.add( StatisticEntry( StatisticsManager.STATISTICS_STATID_USER_GROUPS_ACCESSES, str(month) + "/" + str(year % 1000), random.randrange(5, 15), StatisticsManager.SERIES_GROUP_BY_MEDIUM_ACTIVITY, month, year, StatisticsManager.BINNING_NONE)) db.session.add( StatisticEntry( StatisticsManager.STATISTICS_STATID_USER_GROUPS_ACCESSES, str(month) + "/" + str(year % 1000), random.randrange(2, 6), StatisticsManager.SERIES_GROUP_BY_HIGH_ACTIVITY, month, year, StatisticsManager.BINNING_NONE)) # STATISTICS_STATID_USER_GROUPS_ACCESSES entries db.session.add( StatisticEntry( StatisticsManager.STATISTICS_STATID_USER_GROUPS_AVERAGE, str(month) + "/" + str(year % 1000), random.randrange(20, 120), StatisticsManager.SERIES_GROUP_BY_LOW_ACTIVITY, month, year, StatisticsManager.BINNING_NONE)) db.session.add( StatisticEntry( StatisticsManager.STATISTICS_STATID_USER_GROUPS_AVERAGE, str(month) + "/" + str(year % 1000), random.randrange(5, 15), StatisticsManager.SERIES_GROUP_BY_MEDIUM_ACTIVITY, month, year, StatisticsManager.BINNING_NONE)) db.session.add( StatisticEntry( StatisticsManager.STATISTICS_STATID_USER_GROUPS_AVERAGE, str(month) + "/" + str(year % 1000), random.randrange(2, 6), StatisticsManager.SERIES_GROUP_BY_HIGH_ACTIVITY, month, year, StatisticsManager.BINNING_NONE)) # STATISTICS_STATID_USERCOUNT entries db.session.add( StatisticEntry(StatisticsManager.STATISTICS_STATID_USERCOUNT, str(month) + "/" + str(year % 1000), random.randrange(20, 120), StatisticsManager.SERIES_GENERALUSER, month, year, StatisticsManager.BINNING_NONE)) db.session.add( StatisticEntry(StatisticsManager.STATISTICS_STATID_USERCOUNT, str(month) + "/" + str(year % 1000), random.randrange(5, 15), StatisticsManager.SERIES_SUPERUSER, month, year, StatisticsManager.BINNING_NONE)) db.session.add( StatisticEntry(StatisticsManager.STATISTICS_STATID_USERCOUNT, str(month) + "/" + str(year % 1000), random.randrange(2, 6), StatisticsManager.SERIES_ADMINUSER, month, year, StatisticsManager.BINNING_NONE)) # STATISTICS_STATID_ACCESSES entries db.session.add( StatisticEntry(StatisticsManager.STATISTICS_STATID_ACCESSES, str(month) + "/" + str(year % 1000), random.randrange(20, 120), StatisticsManager.SERIES_CARD_ACCESSES, month, year, StatisticsManager.BINNING_NONE)) db.session.add( StatisticEntry(StatisticsManager.STATISTICS_STATID_ACCESSES, str(month) + "/" + str(year % 1000), random.randrange(20, 120), StatisticsManager.SERIES_WEB_ACCESSES, month, year, StatisticsManager.BINNING_NONE)) # STATISTICS_STATID_LOGINS entries db.session.add( StatisticEntry(StatisticsManager.STATISTICS_STATID_LOGINS, str(month) + "/" + str(year % 1000), random.randrange(20, 120), StatisticsManager.SERIES_SUCCESFULL_LOGINS, month, year, StatisticsManager.BINNING_NONE)) db.session.add( StatisticEntry(StatisticsManager.STATISTICS_STATID_LOGINS, str(month) + "/" + str(year % 1000), random.randrange(20, 120), StatisticsManager.SERIES_FAILED_LOGINS, month, year, StatisticsManager.BINNING_NONE)) # STATISTICS_STATID_SECURITY entries db.session.add( StatisticEntry(StatisticsManager.STATISTICS_STATID_SECURITY, str(month) + "/" + str(year % 1000), random.randrange(20, 120), StatisticsManager.SERIES_SECURITY_FAILED_LOGINS, month, year, StatisticsManager.BINNING_NONE)) db.session.add( StatisticEntry( StatisticsManager.STATISTICS_STATID_SECURITY, str(month) + "/" + str(year % 1000), random.randrange(20, 120), StatisticsManager.SERIES_SECURITY_FAILED_API_AUTH, month, year, StatisticsManager.BINNING_NONE)) db.session.add( StatisticEntry(StatisticsManager.STATISTICS_STATID_SECURITY, str(month) + "/" + str(year % 1000), random.randrange(20, 120), StatisticsManager.SERIES_SECURITY_WORKER_ERRORS, month, year, StatisticsManager.BINNING_NONE)) for day in range(0, 7): daynamesList = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ] dayname = daynamesList[day] dayEntry = StatisticEntry(StatisticsManager.STATISTICS_STATID_WEEKDAYS, dayname, random.randrange(10, 100), 0, 0, 0, day) db.session.add(dayEntry) for door in range(0, 2): doorsnamesList = ["Elfe", "Duftwolke"] doorname = doorsnamesList[door] doorEntry = StatisticEntry( StatisticsManager.STATISTICS_STATID_NODE_ACCESSES, doorname, random.randrange(10, 100), 0, 0, 0, door) db.session.add(doorEntry) db.session.commit()