This repository was archived by the owner on Jun 10, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis.py
More file actions
67 lines (53 loc) · 2.36 KB
/
Copy pathanalysis.py
File metadata and controls
67 lines (53 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import json
import pandas as pd
import re
from datetime import datetime
file_path = 'temp_projects/telegram_april_export/runtime/output/channel_-1003559202666_2026-04-01_to_2026-04-30/matches.jsonl'
data = []
with open(file_path, 'r', encoding='utf-8') as f:
for line in f:
data.append(json.loads(line))
df = pd.DataFrame(data)
df['text'] = df['text'].fillna('').astype(str)
# Global counts from all messages
total_losses = df['text'].str.count('LOSS').sum()
total_wins = df['text'].str.count('WIN').sum()
total_gale = df['text'].str.count('WIN WITH GALE').sum()
# Identify structured entries in reports
# Pattern looks for: Asset, Time, Type (CALL/PUT), and Result
# Note: 'date_utc' is the timestamp in the JSON
pattern = re.compile(r'([A-Z]{3}/[A-Z]{3}(?:-OTC)?)\s+(\d{1,2}:\d{2})\s+(CALL|PUT).*?(LOSS|WIN(?: WITH GALE)?)', re.IGNORECASE)
records = []
for idx, row in df.iterrows():
found = pattern.findall(row['text'])
for m in found:
records.append({
'asset': m[0],
'time': m[1],
'type': m[2].upper(),
'result': m[3].upper(),
'date_utc': row['date_utc']
})
rdf = pd.DataFrame(records)
if not rdf.empty:
rdf['date_dt'] = pd.to_datetime(rdf['date_utc'])
rdf['hour'] = rdf['date_dt'].dt.hour
losses = rdf[rdf['result'] == 'LOSS']
gains = rdf[rdf['result'].str.contains('WIN')]
print(f"1) Total Explicit Losses (Regex): {len(losses)}")
print(f"2) Total Gains (Regex): {len(gains)}")
print(f"3) Loss Rate (from reports): {len(losses)/len(rdf):.2%}" if len(rdf)>0 else "3) Loss Rate: 0%")
print("\n4) Most Common Losing Assets:")
print(losses['asset'].value_counts().head(5).to_string())
print("\n5) Losing Entries by Hour-of-Day:")
print(losses['hour'].value_counts().sort_index().to_string())
# Near-failure: GALE occurrences
gale_wins = rdf[rdf['result'] == 'WIN WITH GALE']
print(f"\n6) Near-failure (WIN WITH GALE): {len(gale_wins)}")
print("\n7) Repeated Textual Pattern around Losses:")
print(f"Direction Bias in Losses: {losses['type'].value_counts().to_dict()}")
else:
print("No structured signals found. Falling back to raw counts.")
print(f"1) Total 'LOSS' mentions: {total_losses}")
print(f"2) Total 'WIN' mentions: {total_wins}")
print(f"6) Total 'WIN WITH GALE' mentions: {total_gale}")