yeref 0.24.31__py3-none-any.whl → 0.24.33__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
@@ -28,6 +28,7 @@ import urllib.parse
28
28
  import zipfile
29
29
  from html import unescape
30
30
  from calendar import monthrange
31
+ from collections import defaultdict
31
32
  # import whisper
32
33
  # pip install openai-whisper
33
34
  from datetime import datetime, timezone, timedelta
@@ -211,7 +212,7 @@ BOT_CADMIN_ = '☐☑'
211
212
  BOT_VARS_ = '{"BOT_PROMO": "#911", "BOT_CHANNEL": 0, "BOT_CHANNELTID": 0, "BOT_GROUP": 0, "BOT_GROUPTID": 0, "BOT_CHATGPT": "", "BOT_GEO": 0, "BOT_TZ": "+00:00", "BOT_DT": "", "BOT_LZ": "en", "BOT_LC": "en", "BOT_ISSTARTED": 0, "BOT_ISMENTIONED": 0}'
212
213
  BOT_LSTS_ = '{"BOT_ADMINS": [], "BOT_COMMANDS": ["/start"]}'
213
214
  USER_VARS_ = '{"USER_TEXT": "", "USER_REACTION": "", "USER_PUSH": "", "USER_EMAIL": "", "USER_PROMO": "", "USER_CONTACT": "", "USER_GEO": "", "USER_UTM": "", "USER_ID": 0, "USER_DT": "", "USER_TZ": "+00:00", "USER_LC": "en", "USER_LZ": "en", "USER_ISADMIN": 0, "USER_ISBLOG": 0, "USER_ISPREMIUM": 0, "USER_BALL": 0, "USER_RAND": 0, "USER_QUIZ": 0, "USER_DICE": 0, "MSGID_PAID": 0, "DATE_TIME": 0}'
214
- USER_LSTS_ = '{"USER_UTMREF": [], "USER_PAYMENTS": [], "USER_TXS": [], "USER_DAU": [], "USER_MAU": []}'
215
+ USER_LSTS_ = '{"USER_UTMREF": [], "USER_PAYMENTS": [], "USER_TXS": [], "USER_DAU": [], "USER_MAU": [], "USER_STATUSES": []}'
215
216
 
216
217
  UB_CONFIG_ = '☑☑☑☐☐☑☑☐☐☐☐☐☐'
217
218
  UB_CMONITOR_ = '☐'
@@ -15816,6 +15817,117 @@ async def upd_user_data(ENT_TID, data, web_app_init_data, PROJECT_USERNAME, BASE
15816
15817
  # endregion
15817
15818
 
15818
15819
 
15820
+ # region unit ecomonics
15821
+ async def return_view_metrics(bot, PROJECT_USERNAME, EXTRA_D, BASE_P):
15822
+ try:
15823
+ schema_name = "USER"
15824
+ if PROJECT_USERNAME == 'FereyBotBot':
15825
+ schema_name = "BOT"
15826
+ elif PROJECT_USERNAME == 'FereyChannelBot':
15827
+ schema_name = "CHANNEL"
15828
+ elif PROJECT_USERNAME == 'FereyGroupBot':
15829
+ schema_name = "GROUPP"
15830
+
15831
+ sql = f"SELECT {schema_name}_TID FROM \"{schema_name}\""
15832
+ data_ents = await db_select_pg(sql, (), BASE_P)
15833
+
15834
+ metrics_by_month = defaultdict(lambda: {
15835
+ "dau": 0,
15836
+ "mau": 0,
15837
+ "wallets": 0,
15838
+ "tx": 0,
15839
+ "tvl": 0,
15840
+ "/start": 0,
15841
+ "/startapp": 0
15842
+ })
15843
+ seen_mau = set()
15844
+ seen_dau = set()
15845
+ wallets_set = set()
15846
+ users_set = set()
15847
+
15848
+ def process_user_rows(rows):
15849
+ for USER_TID, USER_VARS, USER_LSTS in rows:
15850
+ USER_VARS = json.loads(USER_VARS or "{}")
15851
+ USER_LSTS = json.loads(USER_LSTS or "{}")
15852
+ USER_WALLET = USER_VARS.get('USER_WALLET', '')
15853
+ USER_UTM = USER_VARS.get('USER_UTM', '')
15854
+ USER_DT = USER_VARS.get('USER_DT', '')
15855
+ USER_DAU = USER_LSTS.get("USER_DAU", [])
15856
+ USER_MAU = USER_LSTS.get("USER_MAU", [])
15857
+ USER_TXS = USER_LSTS.get("USER_TXS", [])
15858
+
15859
+ if USER_WALLET: wallets_set.add(USER_WALLET)
15860
+ users_set.add(USER_TID)
15861
+
15862
+ for day_str in USER_DAU:
15863
+ dt_day = datetime.strptime(day_str, "%Y-%m-%d")
15864
+ month_key = dt_day.strftime("%Y-%m")
15865
+ if (USER_TID, month_key) not in seen_dau:
15866
+ seen_dau.add((USER_TID, month_key))
15867
+ metrics_by_month[month_key]["dau"] += 1
15868
+
15869
+ for mo_str in USER_MAU:
15870
+ dt_m = datetime.strptime(mo_str + "-01", "%Y-%m-%d")
15871
+ month_key = dt_m.strftime("%Y-%m")
15872
+ if (USER_TID, month_key) not in seen_mau:
15873
+ seen_mau.add((USER_TID, month_key))
15874
+ metrics_by_month[month_key]["mau"] += 1
15875
+ if USER_WALLET:
15876
+ metrics_by_month[month_key]["wallets"] += 1
15877
+
15878
+ for tx in USER_TXS:
15879
+ dt_start = tx.get("DT_START", "")
15880
+ amount = int(tx.get("AMOUNT", "0"))
15881
+ dt_tx = datetime.strptime(dt_start, "%d-%m-%Y_%H-%M-%S")
15882
+ month_key = dt_tx.strftime("%Y-%m")
15883
+ metrics_by_month[month_key]["tx"] += 1
15884
+ metrics_by_month[month_key]["tvl"] += amount
15885
+
15886
+ if USER_DT:
15887
+ dt_obj = datetime.strptime(USER_DT, "%d-%m-%Y_%H-%M-%S")
15888
+ month_key = dt_obj.strftime("%Y-%m")
15889
+ key = "/startapp" if USER_UTM == "/startapp" else "/start"
15890
+ metrics_by_month[month_key][key] += 1
15891
+
15892
+ for item in data_ents:
15893
+ ENT_TID = item[0]
15894
+ sql = f'SELECT USER_TID, USER_VARS, USER_LSTS FROM {schema_name}_{ENT_TID}.USER'
15895
+ data_users = await db_select_pg(sql, (), BASE_P)
15896
+ process_user_rows(data_users)
15897
+
15898
+ sql = f"SELECT USER_TID, USER_VARS, USER_LSTS FROM \"USER\""
15899
+ data_users = await db_select_pg(sql, (), BASE_P)
15900
+ process_user_rows(data_users)
15901
+
15902
+ all_months = sorted(metrics_by_month.keys())
15903
+ f_name = os.path.join(EXTRA_D, "1_metrics.csv")
15904
+ with open(f_name, mode="w", encoding="utf-8", newline="") as csvfile:
15905
+ writer = csv.writer(csvfile, delimiter=',')
15906
+ writer.writerow(["MO", "DAU", "MAU", "Wallets", "Transactions", "TVL", "/start", "/startapp"])
15907
+ for ym in all_months:
15908
+ row = [
15909
+ ym,
15910
+ metrics_by_month[ym]["dau"],
15911
+ metrics_by_month[ym]["mau"],
15912
+ metrics_by_month[ym]["wallets"],
15913
+ metrics_by_month[ym]["tx"],
15914
+ "",
15915
+ metrics_by_month[ym]["/start"],
15916
+ metrics_by_month[ym]["/startapp"],
15917
+ ]
15918
+ writer.writerow(row)
15919
+ f.write("\n")
15920
+ f.write(f"Unique wallet count: {len(wallets_set)}\n")
15921
+ f.write(f"Unique users count: {len(users_set)}\n")
15922
+
15923
+ thumb = types.FSInputFile(os.path.join(EXTRA_D, 'parse.jpg'))
15924
+ await bot.send_document(chat_id=my_tid, document=types.FSInputFile(f_name), thumbnail=thumb)
15925
+ except Exception as e:
15926
+ logger.info(log_ % str(e))
15927
+ await asyncio.sleep(round(random.uniform(0, 1), 2))
15928
+ # endregion
15929
+
15930
+
15819
15931
  # region pst
15820
15932
  async def ch_games(USER_GAMES, game, condition, balls=-1):
15821
15933
  try:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: yeref
3
- Version: 0.24.31
3
+ Version: 0.24.33
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=V3nj4XqxYKFKFqRkwwIiSoJU2ykkMR7SEP00G8uRSaE,1026578
5
+ yeref-0.24.33.dist-info/METADATA,sha256=GsyEJnRZsZi2Fn4axxHWOA1VrrpinHntLHm9RAuRK2c,119
6
+ yeref-0.24.33.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ yeref-0.24.33.dist-info/top_level.txt,sha256=yCQKchWHbfV-3OuQPYRdi2loypD-nmbDJbtt3OuKKkY,6
8
+ yeref-0.24.33.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,,