Skip to content

Commit 7b26858

Browse files
committed
Testing new output path for csv files
1 parent ae9055d commit 7b26858

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

fetcher.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
'''
1313
import access
1414
API_KEY: str = access.MY_KEY
15+
OUTPUT_PATH = '/var/www/html/stats/'
1516

1617
Vector = Dict[str, list]
1718

@@ -36,6 +37,8 @@
3637
}
3738

3839
n_hours: float = 24.0
40+
LONG_LISTENER_MINUTE_THRESHOLD = 5
41+
SHORT_LISTENER_MINUTE_THRESHOLD = 60
3942

4043
'''
4144
This method reinitializes the temporary dictionaries used to
@@ -78,7 +81,7 @@ def snapshot() -> None:
7881
res = requests.get('https://streaming.lahmacun.hu/api/station/1/listeners', headers=headers)
7982
results = res.json()
8083

81-
threshold = datetime.timedelta(minutes=5)
84+
threshold = datetime.timedelta(minutes=LONG_LISTENER_MINUTE_THRESHOLD)
8285

8386
for listener in results:
8487

@@ -146,8 +149,8 @@ def autoFetch() -> None:
146149
1. Converting the 'monitored_data' dictionary to pandas dataframe 'df_monitored'
147150
2. Logging following data to 'computed_data' dictionary :
148151
+ 'Total Listeners'
149-
+ 'Total Valid Listeners'
150-
+ 'Total Ghost Listeners'
152+
+ 'Total Long Listeners'
153+
+ 'Total Short Listeners'
151154
+ 'Total N/A entries'
152155
+ 'Total sessions'
153156
3. Converting 'computed_data' dictionary to pandas dataframe 'df_computed'
@@ -173,12 +176,12 @@ def autoExport() -> None:
173176
total_valid_listeners = sum(df_monitored['valid'])
174177
computed_data['valid'][1] = total_valid_listeners
175178

176-
''' Logging 'Total Ghost Listeners' (less than 60s)
179+
''' Logging 'Total Short Listeners' (less than 60s)
177180
'''
178181
computed_data['valid'][2] = 0
179182
for entry in df_monitored['connected_time']:
180183
if (len(entry) == 1 and
181-
entry[0][1] < datetime.timedelta(seconds=60)
184+
entry[0][1] < datetime.timedelta(seconds=SHORT_LISTENER_MINUTE_THRESHOLD)
182185
):
183186
computed_data['valid'][2] += 1
184187

@@ -202,7 +205,7 @@ def autoExport() -> None:
202205

203206
filename = 'lahma_{}_{}.csv'.format(date, time)
204207

205-
df.to_csv(filename, index=False)
208+
df.to_csv(OUTPUT_PATH + filename, index=False)
206209
print('{}: exporting {}'.format(str(timestamp)[11:-7], filename))
207210

208211
reinitializer()

0 commit comments

Comments
 (0)