Skip to content

Commit

Permalink
Adds iSpindel support to the server (#121)
Browse files Browse the repository at this point in the history
* Adds iSpindel support for the server. iSpindel Server Address should be configured for picobrew.com and Path/URI to /API/iSpindel

* Update session_parser.py

Removed unnecessary comment

* Update config.example.yaml

Fixed typo

* Update config.py

Fixed all caps on ZYMATIC

* Updating to latest master from chiefwgms

* Minor fixes

* Update routes_frontend for latest files

* Fxing iSpindel_graph_socketio javascript call since it exists in index.html
  • Loading branch information
BuckoWA authored Oct 10, 2020
1 parent 4c359ab commit f962fa1
Show file tree
Hide file tree
Showing 14 changed files with 1,038 additions and 689 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ app/sessions/brew/active/*
app/sessions/brew/archive/*
app/sessions/ferm/active/*
app/sessions/ferm/archive/*
app/sessions/iSpindel/active/*
app/sessions/iSpindel/archive/*

scripts/docker/nginx/certs/*

Expand Down
17 changes: 11 additions & 6 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

def create_dir(dir_path):
# create the directory and any missing parent directories, if it doesn't already exist
pathlib.Path(dir_path).mkdir(parents=True, exist_ok=True)
pathlib.Path(dir_path).mkdir(parents=True, exist_ok=True)

def create_app(debug=False):
"""Create an application."""
Expand All @@ -24,9 +24,9 @@ def create_app(debug=False):

# these imports required to be after socketio initialization
from .main.config import MachineType
from .main.model import PicoFermSession, PicoBrewSession
from .main.model import PicoFermSession, PicoBrewSession, iSpindelSession
from .main.routes_frontend import initialize_data
from .main.session_parser import restore_active_sessions, active_brew_sessions, active_ferm_sessions
from .main.session_parser import restore_active_sessions, active_brew_sessions, active_ferm_sessions, active_iSpindel_sessions

from .main import main as main_blueprint

Expand All @@ -36,10 +36,10 @@ def create_app(debug=False):
server_cfg = {}
cfg_file = BASE_PATH.joinpath('config.yaml')
if not pathlib.Path(cfg_file).exists():
# copy config.example.yaml -> config.yaml if config.yaml doesn't exist
# copy config.example.yaml > config.yaml if config.yaml doesn't exist
example_cfg_file = BASE_PATH.joinpath('config.example.yaml')
copyfile(example_cfg_file, cfg_file)

with open(cfg_file, 'r') as f:
server_cfg = yaml.safe_load(f)

Expand All @@ -60,12 +60,14 @@ def create_app(debug=False):
create_dir(app.config['SESSIONS_PATH'].joinpath('brew/archive'))
create_dir(app.config['SESSIONS_PATH'].joinpath('ferm/active'))
create_dir(app.config['SESSIONS_PATH'].joinpath('ferm/archive'))
create_dir(app.config['SESSIONS_PATH'].joinpath('iSpindel/active'))
create_dir(app.config['SESSIONS_PATH'].joinpath('iSpindel/archive'))

with app.app_context():
restore_active_sessions()
initialize_data()
if 'aliases' in server_cfg:
machine_types = [MachineType.ZSERIES, MachineType.ZYMATIC, MachineType.PICOBREW, MachineType.PICOFERM, MachineType.PICOSTILL]
machine_types = [MachineType.ZSERIES, MachineType.ZYMATIC, MachineType.PICOBREW, MachineType.PICOFERM, MachineType.PICOSTILL, MachineType.ISPINDEL]
for mtype in machine_types:
aliases = server_cfg['aliases']
if mtype in aliases and aliases[mtype] is not None:
Expand All @@ -74,6 +76,9 @@ def create_app(debug=False):
if mtype == MachineType.PICOFERM:
active_ferm_sessions[uid] = PicoFermSession()
active_ferm_sessions[uid].alias = aliases[mtype][uid]
elif mtype == MachineType.ISPINDEL:
active_iSpindel_sessions[uid] = iSpindelSession()
active_iSpindel_sessions[uid].alias = aliases[mtype][uid]
else:
active_brew_sessions[uid] = PicoBrewSession()
active_brew_sessions[uid].alias = aliases[mtype][uid]
Expand Down
2 changes: 1 addition & 1 deletion app/main/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
main = Blueprint('main', __name__)

# required to load the API routes
from . import routes_frontend, routes_pico_api, routes_zymatic_api, routes_zseries_api, routes_picoferm_api, routes_picostill_api
from . import routes_frontend, routes_pico_api, routes_zymatic_api, routes_zseries_api, routes_picoferm_api, routes_picostill_api, routes_iSpindel_api
10 changes: 9 additions & 1 deletion app/main/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MachineType(str, Enum):
PICOSTILL = 'PicoStill'
ZSERIES = 'ZSeries'
ZYMATIC = 'Zymatic'

ISPINDEL = 'iSpindel'

# server config
def server_config():
Expand Down Expand Up @@ -65,3 +65,11 @@ def ferm_active_sessions_path():

def ferm_archive_sessions_path():
return current_app.config['SESSIONS_PATH'].joinpath('ferm/archive')


def iSpindel_active_sessions_path():
return current_app.config['SESSIONS_PATH'].joinpath('iSpindel/active')


def iSpindel_archive_sessions_path():
return current_app.config['SESSIONS_PATH'].joinpath('iSpindel/archive')
24 changes: 23 additions & 1 deletion app/main/model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import shutil
from .config import brew_archive_sessions_path, ferm_archive_sessions_path
from .config import brew_archive_sessions_path, ferm_archive_sessions_path, iSpindel_archive_sessions_path


ZYMATIC_LOCATION = {
Expand Down Expand Up @@ -94,3 +94,25 @@ def cleanup(self):
self.voltage = '-'
self.start_time = None
self.data = []


class iSpindelSession():
def __init__(self):
self.file = None
self.filepath = None
self.alias = ''
self.uninit = True
self.voltage = '-'
self.start_time = None
self.data = []

def cleanup(self):
if self.file and self.filepath:
self.file.close()
shutil.move(str(self.filepath), str(iSpindel_archive_sessions_path()))
self.file = None
self.filepath = None
self.uninit = True
self.voltage = '-'
self.start_time = None
self.data = []
Loading

0 comments on commit f962fa1

Please sign in to comment.