yeref 0.24.31__py3-none-any.whl → 0.24.32__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
yeref/yeref.py CHANGED
@@ -15816,6 +15816,117 @@ async def upd_user_data(ENT_TID, data, web_app_init_data, PROJECT_USERNAME, BASE
15816
15816
  # endregion
15817
15817
 
15818
15818
 
15819
+ # region unit ecomonics
15820
+ async def return_view_metrics(bot, PROJECT_USERNAME, EXTRA_D, BASE_P):
15821
+ try:
15822
+ schema_name = "USER"
15823
+ if PROJECT_USERNAME == 'FereyBotBot':
15824
+ schema_name = "BOT"
15825
+ elif PROJECT_USERNAME == 'FereyChannelBot':
15826
+ schema_name = "CHANNEL"
15827
+ elif PROJECT_USERNAME == 'FereyGroupBot':
15828
+ schema_name = "GROUPP"
15829
+
15830
+ sql = f"SELECT {schema_name}_TID FROM \"{schema_name}\""
15831
+ data_ents = await db_select_pg(sql, (), BASE_P)
15832
+
15833
+ metrics_by_month = defaultdict(lambda: {
15834
+ "dau": 0,
15835
+ "mau": 0,
15836
+ "wallets": 0,
15837
+ "tx": 0,
15838
+ "tvl": 0,
15839
+ "/start": 0,
15840
+ "/startapp": 0
15841
+ })
15842
+ seen_mau = set()
15843
+ seen_dau = set()
15844
+ wallets_set = set()
15845
+ users_set = set()
15846
+
15847
+ def process_user_rows(rows):
15848
+ for USER_TID, USER_VARS, USER_LSTS in rows:
15849
+ USER_VARS = json.loads(USER_VARS or "{}")
15850
+ USER_LSTS = json.loads(USER_LSTS or "{}")
15851
+ USER_WALLET = USER_VARS.get('USER_WALLET', '')
15852
+ USER_UTM = USER_VARS.get('USER_UTM', '')
15853
+ USER_DT = USER_VARS.get('USER_DT', '')
15854
+ USER_DAU = USER_LSTS.get("USER_DAU", [])
15855
+ USER_MAU = USER_LSTS.get("USER_MAU", [])
15856
+ USER_TXS = USER_LSTS.get("USER_TXS", [])
15857
+
15858
+ if USER_WALLET: wallets_set.add(USER_WALLET)
15859
+ users_set.add(USER_TID)
15860
+
15861
+ for day_str in USER_DAU:
15862
+ dt_day = datetime.strptime(day_str, "%Y-%m-%d")
15863
+ month_key = dt_day.strftime("%Y-%m")
15864
+ if (USER_TID, month_key) not in seen_dau:
15865
+ seen_dau.add((USER_TID, month_key))
15866
+ metrics_by_month[month_key]["dau"] += 1
15867
+
15868
+ for mo_str in USER_MAU:
15869
+ dt_m = datetime.strptime(mo_str + "-01", "%Y-%m-%d")
15870
+ month_key = dt_m.strftime("%Y-%m")
15871
+ if (USER_TID, month_key) not in seen_mau:
15872
+ seen_mau.add((USER_TID, month_key))
15873
+ metrics_by_month[month_key]["mau"] += 1
15874
+ if USER_WALLET:
15875
+ metrics_by_month[month_key]["wallets"] += 1
15876
+
15877
+ for tx in USER_TXS:
15878
+ dt_start = tx.get("DT_START", "")
15879
+ amount = int(tx.get("AMOUNT", "0"))
15880
+ dt_tx = datetime.strptime(dt_start, "%d-%m-%Y_%H-%M-%S")
15881
+ month_key = dt_tx.strftime("%Y-%m")
15882
+ metrics_by_month[month_key]["tx"] += 1
15883
+ metrics_by_month[month_key]["tvl"] += amount
15884
+
15885
+ if USER_DT:
15886
+ dt_obj = datetime.strptime(USER_DT, "%d-%m-%Y_%H-%M-%S")
15887
+ month_key = dt_obj.strftime("%Y-%m")
15888
+ key = "/startapp" if USER_UTM == "/startapp" else "/start"
15889
+ metrics_by_month[month_key][key] += 1
15890
+
15891
+ for item in data_ents:
15892
+ ENT_TID = item[0]
15893
+ sql = f'SELECT USER_TID, USER_VARS, USER_LSTS FROM {schema_name}_{ENT_TID}.USER'
15894
+ data_users = await db_select_pg(sql, (), BASE_P)
15895
+ process_user_rows(data_users)
15896
+
15897
+ sql = f"SELECT USER_TID, USER_VARS, USER_LSTS FROM \"USER\""
15898
+ data_users = await db_select_pg(sql, (), BASE_P)
15899
+ process_user_rows(data_users)
15900
+
15901
+ all_months = sorted(metrics_by_month.keys())
15902
+ f_name = os.path.join(EXTRA_D, "1_metrics.csv")
15903
+ with open(f_name, mode="w", encoding="utf-8", newline="") as csvfile:
15904
+ writer = csv.writer(csvfile, delimiter=',')
15905
+ writer.writerow(["MO", "DAU", "MAU", "Wallets", "Transactions", "TVL", "/start", "/startapp"])
15906
+ for ym in all_months:
15907
+ row = [
15908
+ ym,
15909
+ metrics_by_month[ym]["dau"],
15910
+ metrics_by_month[ym]["mau"],
15911
+ metrics_by_month[ym]["wallets"],
15912
+ metrics_by_month[ym]["tx"],
15913
+ "",
15914
+ metrics_by_month[ym]["/start"],
15915
+ metrics_by_month[ym]["/startapp"],
15916
+ ]
15917
+ writer.writerow(row)
15918
+ f.write("\n")
15919
+ f.write(f"Unique wallet count: {len(wallets_set)}\n")
15920
+ f.write(f"Unique users count: {len(users_set)}\n")
15921
+
15922
+ thumb = types.FSInputFile(os.path.join(EXTRA_D, 'parse.jpg'))
15923
+ await bot.send_document(chat_id=my_tid, document=types.FSInputFile(f_name), thumbnail=thumb)
15924
+ except Exception as e:
15925
+ logger.info(log_ % str(e))
15926
+ await asyncio.sleep(round(random.uniform(0, 1), 2))
15927
+ # endregion
15928
+
15929
+
15819
15930
  # region pst
15820
15931
  async def ch_games(USER_GAMES, game, condition, balls=-1):
15821
15932
  try:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: yeref
3
- Version: 0.24.31
3
+ Version: 0.24.32
4
4
  Summary: desc-f
5
5
  Author: john smith
6
6
  Dynamic: author
@@ -0,0 +1,8 @@
1
+ yeref/__init__.py,sha256=Qpv3o6Xa78VdLcsSRmctGtpnYE9btpAkCekgGhgJyXM,49
2
+ yeref/l_.py,sha256=LMX_olmJwq-tgoALJCnhV_fGrL_i_43yBLkLIcEVqGo,1176743
3
+ yeref/tonweb.js,sha256=Jf6aFOQ1OIY4q7fINYz-m5LsI3seMus124M5SYYZmtE,443659
4
+ yeref/yeref.py,sha256=4-MPeYeY_tGffgs27L5-p17A05-o-23XPZjgK_r_tTs,1026521
5
+ yeref-0.24.32.dist-info/METADATA,sha256=3XWVL0VpNNaZCK47VF0sZWRukFrE5WD4Owj2jQNEwIw,119
6
+ yeref-0.24.32.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ yeref-0.24.32.dist-info/top_level.txt,sha256=yCQKchWHbfV-3OuQPYRdi2loypD-nmbDJbtt3OuKKkY,6
8
+ yeref-0.24.32.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- yeref/__init__.py,sha256=Qpv3o6Xa78VdLcsSRmctGtpnYE9btpAkCekgGhgJyXM,49
2
- yeref/l_.py,sha256=LMX_olmJwq-tgoALJCnhV_fGrL_i_43yBLkLIcEVqGo,1176743
3
- yeref/tonweb.js,sha256=Jf6aFOQ1OIY4q7fINYz-m5LsI3seMus124M5SYYZmtE,443659
4
- yeref/yeref.py,sha256=XWmU_poRipZ6uaBVdxaW3OoSapxu87eNO8lovv3yzL0,1021799
5
- yeref-0.24.31.dist-info/METADATA,sha256=8BtXH2OSMyxqfLxj2mUPE-HJhCD0B5g_ftY3mEB_NV8,119
6
- yeref-0.24.31.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
- yeref-0.24.31.dist-info/top_level.txt,sha256=yCQKchWHbfV-3OuQPYRdi2loypD-nmbDJbtt3OuKKkY,6
8
- yeref-0.24.31.dist-info/RECORD,,