Skip to content

Commit d8bfb04

Browse files
authored
Merge pull request #157 from phate999/master
Fixed timestamps in MSS
2 parents 65e9b5c + 9ad27d2 commit d8bfb04

4 files changed

Lines changed: 45 additions & 29 deletions

File tree

Mobile_Site_Survey/Mobile_Site_Survey.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def get(self):
3333
time.sleep(1)
3434
# Set timestamp immediately for manual tests so indicator shows
3535
if dispatcher:
36-
dispatcher.timestamp = datetime.datetime.utcnow().timestamp()
36+
dispatcher.timestamp = time.time() # time.time() always returns UTC timestamp
3737

3838
if dispatcher:
3939
dispatcher.manual = True
@@ -75,8 +75,15 @@ def get(self):
7575
# Add survey running status
7676
if dispatcher:
7777
config["survey_running"] = dispatcher.timestamp is not None
78+
# Calculate total data used across all modems
79+
total_data_mb = 0.0
80+
if dispatcher.total_bytes:
81+
total_bytes_sum = sum(dispatcher.total_bytes.values())
82+
total_data_mb = round(total_bytes_sum / 1000 / 1000, 2)
83+
config["total_data_used_mb"] = total_data_mb
7884
else:
7985
config["survey_running"] = False
86+
config["total_data_used_mb"] = 0.0
8087

8188
self.write(json.dumps(config))
8289
return
@@ -264,7 +271,7 @@ def _start_survey(self, latlong):
264271
cp.log('---> Starting Survey <---')
265272
self._initialize_modems()
266273
if self.timestamp is None: # If not triggered remotely
267-
self.timestamp = datetime.datetime.utcnow().timestamp()
274+
self.timestamp = time.time() # time.time() always returns UTC timestamp
268275
self._start_surveyors()
269276
self._run_tests_on_modems()
270277
cp.log('---> Survey Complete <---')
@@ -287,10 +294,8 @@ def _run_tests_on_modems(self):
287294
routing_tables = cp.get('config/routing/tables')
288295
with concurrent.futures.ThreadPoolExecutor(len(self.modems)) as executor:
289296
executor.map(run_tests, self.modems)
290-
# Convert UTC timestamp to local time for display
291-
utc_time = datetime.datetime.utcfromtimestamp(self.timestamp)
292-
local_time = utc_time.replace(tzinfo=datetime.timezone.utc).astimezone()
293-
pretty_timestamp = local_time.strftime('%H:%M:%S %m/%d/%Y')
297+
# Format UTC timestamp for display
298+
pretty_timestamp = time.strftime('%H:%M:%S %m/%d/%Y', time.gmtime(self.timestamp))
294299
pretty_lat = '{:.6f}'.format(float(self.lat)) if self.lat is not None else '0.000000'
295300
pretty_lon = '{:.6f}'.format(float(self.long)) if self.long is not None else '0.000000'
296301
# Title will be added with the detailed results in run_tests function
@@ -469,10 +474,10 @@ def debug_log(msg):
469474

470475
def log_all(msg, logs):
471476
"""Write consistent messages across all logs"""
472-
logstamp = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
477+
logstamp = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime())
473478
cp.log(msg)
474479
logs.append(f'{logstamp} {msg}')
475-
dispatcher.results = f'{msg}\n\n' + dispatcher.results
480+
dispatcher.results = f'{msg}\n\n' + dispatcher.results[:32000]
476481

477482

478483
def ping(host, iface):
@@ -707,12 +712,7 @@ def run_tests(modem):
707712
product = modem
708713
cur_plmn = None
709714

710-
# Latency test:
711-
pong = ping('8.8.8.8', iface)
712-
if pong.get('loss') == 100.0:
713-
latency = 'FAIL'
714-
else:
715-
latency = round(pong.get('avg'))
715+
latency = None
716716

717717
# Calculate packet loss
718718
try:
@@ -755,17 +755,17 @@ def run_tests(modem):
755755
retries += 1
756756
cp.log(f'Attempt {retries} of 3 to get_best_server() failed: {e}')
757757

758-
logstamp = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
758+
logstamp = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime())
759759
logs.append(f'{logstamp} Starting Download Test on {product} {carrier}.')
760760
cp.log(f'Starting Download Test on {product} {carrier}.')
761761
ookla.download() # Ookla Download Test
762762
if wan_type == 'mdm': # Capture CA Bands for modems
763763
diagnostics = cp.get(f'status/wan/devices/{modem}/diagnostics')
764-
logstamp = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
764+
logstamp = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime())
765765
logs.append(f'{logstamp} Starting Upload Test on {product} {carrier}.')
766766
cp.log(f'Starting Upload Test on {product} {carrier}.')
767767
ookla.upload(pre_allocate=False) # Ookla upload test
768-
logstamp = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
768+
logstamp = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime())
769769
logs.append(f'{logstamp} Speedtest Complete on {product} {carrier}.')
770770
cp.log(f'Speedtest Complete on {product} {carrier}.')
771771

@@ -789,8 +789,9 @@ def run_tests(modem):
789789
log_all(msg, logs)
790790

791791
# SEND TO SERVER:
792-
pretty_timestamp = datetime.datetime.utcfromtimestamp(dispatcher.timestamp).strftime('%Y-%m-%d %H:%M:%S')
793-
post_success = ''
792+
# Use time.gmtime() to ensure UTC time regardless of system timezone
793+
pretty_timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(dispatcher.timestamp))
794+
post_success = '✓ Done'
794795
if dispatcher.config.get("send_to_server"):
795796
try:
796797
post_success = '⇪ 5g-ready:❌ '
@@ -924,15 +925,13 @@ def run_tests(modem):
924925
serdis, rfband, rfband_5g, scell0, scell1, scell2, scell3]
925926
debug_log(f'ROW: {row}')
926927
text = ','.join(str(x) for x in row) + '\n'
927-
logstamp = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
928+
logstamp = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime())
928929
logs.append(f'{logstamp} Results: {text}')
929930
cp.log(f'Results: {text}')
930931
# cp.put('config/system/desc', text[:1000])
931932
# Get timestamp and coordinates for the title
932933
if dispatcher:
933-
utc_time = datetime.datetime.utcfromtimestamp(dispatcher.timestamp)
934-
local_time = utc_time.replace(tzinfo=datetime.timezone.utc).astimezone()
935-
pretty_timestamp = local_time.strftime('%H:%M:%S %m/%d/%Y')
934+
pretty_timestamp = time.strftime('%H:%M:%S %m/%d/%Y', time.gmtime(dispatcher.timestamp))
936935
pretty_lat = '{:.6f}'.format(float(dispatcher.lat)) if dispatcher.lat is not None else '0.000000'
937936
pretty_lon = '{:.6f}'.format(float(dispatcher.long)) if dispatcher.long is not None else '0.000000'
938937

@@ -944,7 +943,7 @@ def run_tests(modem):
944943
pretty_results = title + f' ┣┅┅┅ ☏{carrier} {cur_plmn}{packet_loss_percent}% loss ({tx - rx} of {tx})\n' \
945944
f' ┣┅┅┅ ↓{download}Mbps ↑{upload}Mbps ⏱{latency}ms\n' \
946945
f' ┣┅┅┅ ⛁ {server}\n' \
947-
f' ┗┅┅┅ {post_success}{total_mb_used}MB total used.'
946+
f' ┗┅┅┅ {post_success}'
948947
log_all(pretty_results, logs)
949948
except Exception as e:
950949
msg = f'Exception formatting results: {e}'
@@ -965,7 +964,7 @@ def run_tests(modem):
965964
# CREATE CSV IF IT DOESN'T EXIST:
966965
debug_log(' '.join(os.listdir(results_dir)))
967966
if not os.path.isfile(f'{results_dir}/{filename}'):
968-
logstamp = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
967+
logstamp = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime())
969968
logs.append(f'{logstamp} {filename} not found.')
970969
cp.log(f'{filename} not found.')
971970
with open(f'{results_dir}/{filename}', 'wt') as f:
@@ -980,7 +979,7 @@ def run_tests(modem):
980979
'RF Band 5G', 'SCELL0', 'SCELL1', 'SCELL2', 'SCELL3']
981980
line = ','.join(header) + '\n'
982981
f.write(line)
983-
logstamp = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
982+
logstamp = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime())
984983
logs.append(f'{logstamp} Created new {filename} file.')
985984
cp.log(f'Created new {filename} file.')
986985

Mobile_Site_Survey/index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ <h2><i class="fas fa-chart-line"></i> Survey Results</h2>
214214
<span class="stat-label">Last Test:</span>
215215
<span class="stat-value" id="last-test">Never</span>
216216
</div>
217+
<div class="stat-item">
218+
<span class="stat-label">Total Data Used:</span>
219+
<span class="stat-value" id="total-data-used">0.00 MB</span>
220+
</div>
217221
</div>
218222
</div>
219223
<div class="results-content">
@@ -238,4 +242,4 @@ <h2><i class="fas fa-chart-line"></i> Survey Results</h2>
238242

239243
<script src="script.js"></script>
240244
</body>
241-
</html>
245+
</html>

Mobile_Site_Survey/package.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ firmware_major = 7
88
firmware_minor = 25
99
version_major = 3
1010
version_minor = 0
11-
version_patch = 0
11+
version_patch = 1
1212
uuid = 98b31c39-f649-43f3-b9f4-276a5d8824bf

Mobile_Site_Survey/script.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class MobileSiteSurvey {
147147
const config = await response.json();
148148
this.populateForm(config);
149149
this.updateResults(config.results);
150+
this.updateTotalDataUsed(config.total_data_used_mb);
150151
this.showToast('Configuration loaded successfully', 'success');
151152
} catch (error) {
152153
console.error('Error loading config:', error);
@@ -206,6 +207,17 @@ class MobileSiteSurvey {
206207
document.getElementById('last-test').textContent = this.lastTestTime || 'Never';
207208
}
208209

210+
updateTotalDataUsed(totalDataMb) {
211+
const element = document.getElementById('total-data-used');
212+
if (element) {
213+
if (totalDataMb !== undefined && totalDataMb !== null) {
214+
element.textContent = `${totalDataMb.toFixed(2)} MB`;
215+
} else {
216+
element.textContent = '0.00 MB';
217+
}
218+
}
219+
}
220+
209221
async runSurvey() {
210222
try {
211223
this.showLoading(true, 'Running Survey...');
@@ -350,6 +362,7 @@ class MobileSiteSurvey {
350362
this.updateResults(config.results);
351363
this.updateStatusIndicators();
352364
this.updateSurveyStatus(config);
365+
this.updateTotalDataUsed(config.total_data_used_mb);
353366
} catch (error) {
354367
console.error('Polling error:', error);
355368
// Don't show error toasts for polling failures to avoid spam
@@ -560,4 +573,4 @@ window.addEventListener('beforeunload', () => {
560573
// Export for potential module usage
561574
if (typeof module !== 'undefined' && module.exports) {
562575
module.exports = MobileSiteSurvey;
563-
}
576+
}

0 commit comments

Comments
 (0)