def getRoast(): d = {} try: config.logger.debug("roast:getRoast()") aw = config.app_window p = aw.getProfile() d = getTemplate(p) # id => roast_id if "id" in d: d["roast_id"] = d["id"] del d["id"] # start_weight => amount if "start_weight" in d: d["amount"] = d["start_weight"] del d["start_weight"] else: d["amount"] = 0 if "computed" in p: cp = p["computed"] util.addNum2dict(cp, "det", d, "CM_ETD", 0, 100, 1) util.addNum2dict(cp, "dbt", d, "CM_BTD", 0, 100, 1) if aw.qmc.plus_store: d["location"] = aw.qmc.plus_store if aw.qmc.plus_coffee: d["coffee"] = aw.qmc.plus_coffee else: d["coffee"] = None if aw.qmc.plus_blend_spec: d["blend"] = aw.qmc.plus_blend_spec else: d["blend"] = None util.addTemp2dict(p, "ambientTemp", d, "temperature") util.addNum2dict(p, "ambient_pressure", d, "pressure", 800, 1200, 1) util.addNum2dict(p, "ambient_humidity", d, "humidity", 0, 100, 1) util.addString2dict(p, "roastingnotes", d, "notes", 1023) if aw.qmc.background and aw.qmc.backgroundprofile: bp = aw.qmc.backgroundprofile template = getTemplate(bp) d["template"] = template # if profile is already saved, that modification date is send along to the server instead the timestamp # of the moment the record is queued if not aw.curFile is None: d["modified_at"] = util.epoch2ISO8601( util.getModificationDate(aw.curFile)) except Exception as e: import sys _, _, exc_tb = sys.exc_info() config.logger.error("roast: Exception in getRoast() line %s: %s", exc_tb.tb_lineno, e) return d
def getTemplate(bp): config.logger.debug("roast:getTemplate()") d = {} try: aw = config.app_window util.addNum2dict(bp, "roastbatchnr", d, "batch_number", 0, 65534, 0) if "batch_number" in d and d["batch_number"]: util.addString2dict(bp, "roastbatchprefix", d, "batch_prefix", 50) util.addNum2dict(bp, "roastbatchpos", d, "batch_pos", 0, 255, 0) if "roastepoch" in bp: d["date"] = util.epoch2ISO8601(bp["roastepoch"]) try: gmt_offset = util.limitnum(-60000, 60000, util.getGMToffset()) if gmt_offset is not None: d["GMT_offset"] = gmt_offset except: pass if "weight" in bp: if bp["weight"][0]: try: w = util.limitnum( 0, 65534, aw.convertWeight( bp["weight"][0], aw.qmc.weight_units.index(bp["weight"][2]), aw.qmc.weight_units.index("Kg"))) if w is not None: d["start_weight"] = util.float2floatMin(w, 3) # in kg except: pass if bp["weight"][1]: try: w = util.limitnum( 0, 65534, aw.convertWeight( bp["weight"][1], aw.qmc.weight_units.index(bp["weight"][2]), aw.qmc.weight_units.index("Kg"))) if w is not None: d["end_weight"] = util.float2floatMin(w, 3) # in kg except: pass if "density_roasted" in bp: if bp["density_roasted"][0]: try: n = util.limitnum(0, 1000, bp["density_roasted"][0]) if n is not None: d["density_roasted"] = util.float2floatMin(n, 1) except: pass util.add2dict(bp, config.uuid_tag, d, "id") util.addNum2dict(bp, "moisture_roasted", d, "moisture", 0, 100, 1) util.addString2dict(bp, "title", d, "label", 255) util.addString2dict(bp, "roastertype", d, "machine", 50) util.addString2dict(bp, "machinesetup", d, "setup", 50) util.addNum2dict(bp, "whole_color", d, "whole_color", 0, 255, 0) util.addNum2dict(bp, "ground_color", d, "ground_color", 0, 255, 0) if ("whole_color" in d or "ground_color" in d): util.addString2dict(bp, "color_system", d, "color_system", 25) if "computed" in bp: cp = bp["computed"] util.addAllTemp2dict(cp, d, [("CHARGE_ET", "charge_temp_ET"), ("CHARGE_BT", "charge_temp"), ("TP_BT", "TP_temp"), ("DRY_BT", "DRY_temp"), ("FCs_BT", "FCs_temp"), ("FCe_BT", "FCe_temp"), ("DROP_BT", "drop_temp"), ("DROP_ET", "drop_temp_ET")]) util.addAllTime2dict(cp, d, [ "TP_time", "DRY_time", "FCs_time", "FCe_time", ("DROP_time", "drop_time") ]) if "finishphasetime" in cp: util.addTime2dict(cp, "finishphasetime", d, "DEV_time") if "totaltime" in cp: v = util.limitnum( 0, 100, util.float2floatMin( cp["finishphasetime"] / cp["totaltime"] * 100, 1)) if v is not None: d["DEV_ratio"] = v util.addNum2dict(cp, "AUC", d, "AUC", 0, 10000, 0) util.addTemp2dict(cp, "AUCbase", d, "AUC_base") except Exception as e: import sys _, _, exc_tb = sys.exc_info() config.logger.error("roast: Exception in getTemplate() line %s: %s", exc_tb.tb_lineno, e) return d
def getRoast(): d = {} try: config.logger.debug("roast:getRoast()") aw = config.app_window p = aw.getProfile() d = getTemplate(p) # id => roast_id if "id" in d: d["roast_id"] = d["id"] del d["id"] # start_weight => amount if "start_weight" in d: d["amount"] = d["start_weight"] del d["start_weight"] else: d["amount"] = 0 # computed values added just for the profile, but not for the profiles template try: if "computed" in p: cp = p["computed"] if "det" in cp: util.addTemp2dict(cp, "det", d, "CM_ETD") if "dbt" in cp: util.addTemp2dict(cp, "dbt", d, "CM_BTD") #### Energy Consumption data only added if not zero util.addAllNum2dict( cp, d, [ # energy consumption by source type in BTU "BTU_ELEC", "BTU_LPG", "BTU_NG", # energy consumption by process in BTU "BTU_roast", "BTU_preheat", "BTU_bbp", "BTU_cooling", # total energy conumption per batch "BTU_batch" ], None, # no min limit None, # no max limit 1, # 1 decimal places ) util.addAllNum2dict( cp, d, [ # CO2 production by process in g "CO2_roast", "CO2_preheat", "CO2_bbp", "CO2_cooling", # total CO2 production per batch "CO2_batch" ], None, # no min limit None, # no max limit 3, # 3 decimal places factor=1 / 1000, # CO2 data is forwarded in kg (instead of the Artisan internal g) ) except Exception as e: config.logger.info("roast: Exception in getRoast() %s", e) if aw.qmc.plus_store: d["location"] = aw.qmc.plus_store else: d["location"] = None if aw.qmc.plus_coffee: d["coffee"] = aw.qmc.plus_coffee else: d["coffee"] = None # we neeed to explicitly add empty selections otherwise the coffee cannot be deleted from the online record if aw.qmc.plus_blend_spec and aw.qmc.plus_coffee is None: d["blend"] = trimBlendSpec(aw.qmc.plus_blend_spec) else: d["blend"] = None # we neeed to explicitly add empty selections otherwise the coffee cannot be deleted from the online record # ensure that location is None if neither coffee nor blend is set if d["coffee"] is None and d["blend"] is None and d[ "location"] is not None: d["location"] = None try: util.addTemp2dict(p, "ambientTemp", d, "temperature") util.addNum2dict(p, "ambient_pressure", d, "pressure", 800, 1200, 1) util.addNum2dict(p, "ambient_humidity", d, "humidity", 0, 100, 1) except Exception as e: config.logger.info("roast: Exception in getRoast() %s", e) try: util.addString2dict(p, "roastingnotes", d, "notes", 1023) except Exception as e: config.logger.info("roast: Exception in getRoast() %s", e) if aw.qmc.background and aw.qmc.backgroundprofile: bp = aw.qmc.backgroundprofile template = getTemplate(bp) d["template"] = template # if profile is already saved, that modification date is send along to the server instead the timestamp # of the moment the record is queued if aw.curFile is not None: d["modified_at"] = util.epoch2ISO8601( util.getModificationDate(aw.curFile)) except Exception as e: import sys _, _, exc_tb = sys.exc_info() config.logger.error("roast: Exception in getRoast() line %s: %s", exc_tb.tb_lineno, e) return {} return d