Skip to content

Commit

Permalink
test exam branch, feature implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
AvangardAA committed Nov 2, 2023
1 parent f7e5e74 commit 3fe9e72
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
8 changes: 6 additions & 2 deletions algo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from fastapi import FastAPI

from functions.funcs import hist_data, user_hist_data, predict_users, predict_user, total_time_user, total_time_avg, \
gdprf, post_metrics, get_reports
gdprf, post_metrics, get_reports, get_uuser_list_exam
from functions.utils import transform_metrics_list
from models import InputData

Expand Down Expand Up @@ -86,4 +86,8 @@ async def forget_gdpr(userId: str):
if not userId:
return {"err": "missing id"}

return await gdprf(userId)
return await gdprf(userId)

@app.get('/api/users/list')
async def get_user_list_exam():
return await get_uuser_list_exam()
33 changes: 33 additions & 0 deletions functions/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,37 @@ async def get_reports(reportname, ffrom, to):

return calculate_metrics_result(user_appearances, daily_sum, daily_count, weekly_sum, weekly_count, reslist)

async def helper_function_exam():
c = 0
users_data = fetch(c)
q = int(users_data['total'])

file_path = os.path.join(os.getcwd(), "log_exam.txt")
if os.path.exists(file_path) and os.path.isfile(file_path):
return

while q > 0:
for user in users_data['data']:
if user["lastSeenDate"] is None:
continue
else:
ts = int(datetime.fromisoformat(user["lastSeenDate"]).timestamp())
doc = {"username": user['nickname'], "userId": user["userId"], "firstSeen": transform_from_iso_format(ts)}
with open("log_exam.txt", 'a') as file:
json.dump(doc, file)
file.write('\n')
q -= len(users_data['data'])
c += len(users_data['data'])
users_data = fetch(c)

async def get_uuser_list_exam():
await helper_function_exam()
with open('log_exam.txt', 'r') as file:
file_contents = file.read()

json_dicts = file_contents.splitlines()
parsed_dicts = [json.loads(json_str) for json_str in json_dicts]

return parsed_dicts

""

0 comments on commit 3fe9e72

Please sign in to comment.