Skip to content

Commit

Permalink
Add version code display
Browse files Browse the repository at this point in the history
Resolves scottgchin#41
  • Loading branch information
HazardCreative committed Feb 13, 2019
1 parent afc188c commit 77e6893
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 57 deletions.
117 changes: 66 additions & 51 deletions src/server/server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'''RotorHazard server script'''
RELEASE_VERSION = "1.1.0 (development)" # Public release version code
SERVER_API = 11 # Server API version
NODE_API_BEST = 13 # Most recent node API

import os
import sys
Expand Down Expand Up @@ -96,6 +98,20 @@
Config['GENERAL']['configFile'] = -1
print 'Configuration file invalid, using defaults'


INTERFACE = get_hardware_interface()
RACE = get_race_state() # For storing race management variables

PROGRAM_START = datetime.now()
RACE_START = datetime.now() # Updated on race start commands
RACE_DURATION_MS = 0 # calculated when race is stopped

Race_laps_winner_name = None # set to name of winner in first-to-X-laps race
RACE_STATUS_TIED_STR = 'Race is tied; continuing' # shown when Most Laps Wins race tied
RACE_STATUS_CROSSING = 'Waiting for cross' # indicator for Most Laps Wins race

Use_imdtabler_jar_flag = False # set True if IMDTabler.jar is available

#
# Translation functions
#
Expand Down Expand Up @@ -136,18 +152,53 @@ def getAllLanguages():
# return full language dictionary
return Languages

INTERFACE = get_hardware_interface()
RACE = get_race_state() # For storing race management variables
#
# Server Info
#

PROGRAM_START = datetime.now()
RACE_START = datetime.now() # Updated on race start commands
RACE_DURATION_MS = 0 # calculated when race is stopped
def buildServerInfo():
server_info = "<ul>"

Race_laps_winner_name = None # set to name of winner in first-to-X-laps race
RACE_STATUS_TIED_STR = 'Race is tied; continuing' # shown when Most Laps Wins race tied
RACE_STATUS_CROSSING = 'Waiting for cross' # indicator for Most Laps Wins race
# Release Version
server_info += "<li>" + __("Version") + ": " + str(RELEASE_VERSION) + "</li>"

Use_imdtabler_jar_flag = False # set True if IMDTabler.jar is available
# Server API
server_info += "<li>" + __("Server API") + ": " + str(SERVER_API) + "</li>"

# Node API levels
node_api_level = False
node_api_match = True
if INTERFACE.nodes[0].api_level:
node_api_level = INTERFACE.nodes[0].api_level

node_api_levels = []
for node in INTERFACE.nodes:
node_api_levels.append(node.api_level)
if node.api_level is not node_api_level:
node_api_match = False

server_info += "<li>" + __("Node API") + ": "
if node_api_level:
if node_api_match:
server_info += str(node_api_level)
else:
server_info += "[ "
for idx, level in node_api_levels:
server_info += str(idx+1) + ":" + str(level) + " "
server_info += "]"
else:
server_info += "None (Delta5)"

server_info += "</li>"

if node_api_match is False or node_api_level < NODE_API_BEST:
# Show Recommended API notice
server_info += "<li><strong>" + __("Node Update Available") + ": " + str(NODE_API_BEST) + "</strong></li>"

server_info += "</ul>"

print server_info
return server_info


#
Expand Down Expand Up @@ -3169,49 +3220,13 @@ def restore_table(class_type, table_query_data, match_name='name'):
INTERFACE.set_history_expire_global(int(getOption("HistoryExpireDuration")))

# Set current heat on startup
RACE.current_heat = Heat.query.first().heat_id

# Test data - Current laps
# DB.session.add(CurrentLap(node_index=2, pilot_id=2, lap_id=0, lap_time_stamp=1000, lap_time=1000, lap_time_formatted=time_format(1000)))
# DB.session.add(CurrentLap(node_index=2, pilot_id=2, lap_id=1, lap_time_stamp=11000, lap_time=10000, lap_time_formatted=time_format(10000)))
# DB.session.add(CurrentLap(node_index=2, pilot_id=2, lap_id=2, lap_time_stamp=21000, lap_time=10000, lap_time_formatted=time_format(10000)))
# DB.session.add(CurrentLap(node_index=3, pilot_id=3, lap_id=0, lap_time_stamp=1000, lap_time=1000, lap_time_formatted=time_format(1000)))
# DB.session.add(CurrentLap(node_index=3, pilot_id=3, lap_id=1, lap_time_stamp=12000, lap_time=11000, lap_time_formatted=time_format(11000)))
# DB.session.add(CurrentLap(node_index=3, pilot_id=3, lap_id=2, lap_time_stamp=24000, lap_time=12000, lap_time_formatted=time_format(12000)))
# DB.session.add(CurrentLap(node_index=4, pilot_id=4, lap_id=0, lap_time_stamp=1000, lap_time=1000, lap_time_formatted=time_format(1000)))
# DB.session.add(CurrentLap(node_index=4, pilot_id=4, lap_id=1, lap_time_stamp=12000, lap_time=11000, lap_time_formatted=time_format(11000)))
# DB.session.add(CurrentLap(node_index=1, pilot_id=1, lap_id=0, lap_time_stamp=1000, lap_time=1000, lap_time_formatted=time_format(1000)))
# DB.session.add(CurrentLap(node_index=1, pilot_id=1, lap_id=1, lap_time_stamp=13000, lap_time=12000, lap_time_formatted=time_format(12000)))
# DB.session.commit()

# Test data - SavedRace
# db_init()
# on_add_heat()
# DB.session.add(SavedRace(round_id=1, heat_id=2, node_index=2, pilot_id=2, lap_id=0, lap_time_stamp=1000, lap_time=1000, lap_time_formatted=time_format(1000)))
# DB.session.add(SavedRace(round_id=1, heat_id=2, node_index=2, pilot_id=2, lap_id=1, lap_time_stamp=15000, lap_time=14000, lap_time_formatted=time_format(14000)))
# DB.session.add(SavedRace(round_id=1, heat_id=2, node_index=2, pilot_id=2, lap_id=2, lap_time_stamp=30000, lap_time=15000, lap_time_formatted=time_format(15000)))
# DB.session.add(SavedRace(round_id=1, heat_id=2, node_index=3, pilot_id=3, lap_id=0, lap_time_stamp=1500, lap_time=1500, lap_time_formatted=time_format(1500)))
# DB.session.add(SavedRace(round_id=1, heat_id=2, node_index=3, pilot_id=3, lap_id=1, lap_time_stamp=15000, lap_time=13500, lap_time_formatted=time_format(13500)))
# DB.session.add(SavedRace(round_id=1, heat_id=2, node_index=1, pilot_id=1, lap_id=0, lap_time_stamp=750, lap_time=750, lap_time_formatted=time_format(750)))
# DB.session.add(SavedRace(round_id=1, heat_id=2, node_index=1, pilot_id=1, lap_id=1, lap_time_stamp=10750, lap_time=10000, lap_time_formatted=time_format(10000)))
# DB.session.commit()
# DB.session.add(SavedRace(round_id=1, heat_id=1, node_index=2, pilot_id=2, lap_id=0, lap_time_stamp=1000, lap_time=1000, lap_time_formatted=time_format(1000)))
# DB.session.add(SavedRace(round_id=1, heat_id=1, node_index=2, pilot_id=2, lap_id=1, lap_time_stamp=15000, lap_time=14000, lap_time_formatted=time_format(14000)))
# DB.session.add(SavedRace(round_id=1, heat_id=1, node_index=2, pilot_id=2, lap_id=2, lap_time_stamp=30000, lap_time=15000, lap_time_formatted=time_format(15000)))
# DB.session.add(SavedRace(round_id=1, heat_id=1, node_index=3, pilot_id=3, lap_id=0, lap_time_stamp=1500, lap_time=1500, lap_time_formatted=time_format(1500)))
# DB.session.add(SavedRace(round_id=1, heat_id=1, node_index=3, pilot_id=3, lap_id=1, lap_time_stamp=15000, lap_time=13500, lap_time_formatted=time_format(13500)))
# DB.session.add(SavedRace(round_id=1, heat_id=1, node_index=1, pilot_id=1, lap_id=0, lap_time_stamp=750, lap_time=750, lap_time_formatted=time_format(750)))
# DB.session.add(SavedRace(round_id=1, heat_id=1, node_index=1, pilot_id=1, lap_id=1, lap_time_stamp=10750, lap_time=10000, lap_time_formatted=time_format(10000)))
# DB.session.commit()
# DB.session.add(SavedRace(round_id=2, heat_id=1, node_index=2, pilot_id=2, lap_id=0, lap_time_stamp=1000, lap_time=1000, lap_time_formatted=time_format(1000)))
# DB.session.add(SavedRace(round_id=2, heat_id=1, node_index=2, pilot_id=2, lap_id=1, lap_time_stamp=16000, lap_time=15000, lap_time_formatted=time_format(15000)))
# DB.session.add(SavedRace(round_id=2, heat_id=1, node_index=2, pilot_id=2, lap_id=2, lap_time_stamp=31000, lap_time=16000, lap_time_formatted=time_format(16000)))
# DB.session.add(SavedRace(round_id=2, heat_id=1, node_index=3, pilot_id=3, lap_id=0, lap_time_stamp=1500, lap_time=1500, lap_time_formatted=time_format(1500)))
# DB.session.add(SavedRace(round_id=2, heat_id=1, node_index=3, pilot_id=3, lap_id=1, lap_time_stamp=16000, lap_time=14500, lap_time_formatted=time_format(14500)))
# DB.session.add(SavedRace(round_id=2, heat_id=1, node_index=1, pilot_id=1, lap_id=0, lap_time_stamp=750, lap_time=750, lap_time_formatted=time_format(750)))
# DB.session.add(SavedRace(round_id=2, heat_id=1, node_index=1, pilot_id=1, lap_id=1, lap_time_stamp=11750, lap_time=11000, lap_time_formatted=time_format(11000)))
# DB.session.commit()
if Heat.query.first():
RACE.current_heat = Heat.query.first().heat_id

# collect server info for About panel
setOption("serverInfo", buildServerInfo())

# Start HTTP server
if __name__ == '__main__':
port_val = Config['GENERAL']['HTTP_PORT']
print "Running http server at port " + str(port_val)
Expand Down
7 changes: 1 addition & 6 deletions src/server/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,7 @@
<div id="about" class="mfp-hide popup-basic">
<h2>{{ __("About RotorHazard") }}</h2>
<div class="popup-content">
<ul>
<li>Version: 1.1.0</li>
<li>Server API: 11</li>
<li>Node API: --</li>
<li>Recommended Node API: 12</li>
</ul>
{{ getOption("serverInfo") | safe }}
</div>
</div>
</body>
Expand Down

0 comments on commit 77e6893

Please sign in to comment.