def get_the_map(ccTremb): import modules.x_database as db """ Method asks the user to select a map, and returns all the credentials for that map. """ # Access the maps database cMaps = db.maps_db(ccTremb) xParam = {} xRestr = {"_id": 0} dMap_query = cMaps.find(xParam, xRestr) # analyse the query iNo_of_maps = 0 dMap_copy = [] for dMap in dMap_query: iNo_of_maps += 1 dMap_copy.append(dMap) print("\nOn which map are you working?") sMenu = "0: No map\n" iCnt = 0 # Display all the options for the map for one_map in dMap_copy: iCnt += 1 xScale = "{0:,}".format(int( one_map["fScale"])) # ","@1k ommas every 1000's sTxt = "{0}: {1}, {2} 1:{3}\n" sMenu += sTxt.format(iCnt, one_map["sRegion"], one_map["iYear"], xScale) sMenu += "99:Invalid choice will exit this sub menu" print(sMenu) sInput = input() if sInput.isnumeric() == False: # An inbuilt 'abort' system where the user can enter 'x' to exit. print("\n\aInput is not a numeric value. Returning to menu") return None # Get the scale iInput = int(sInput) fScale = None if (iInput == 0): print("\n\aA map must be selected. Returning") return None elif (iInput > iCnt): print("\n\aChoice out of range. Returning to menu") return None else: iIdx = iInput - 1 return dMap_copy[iIdx]
def mm_ampersand(): """ Manually read the database (Edit the function for results)""" import modules.x_misc as misc import modules.x_database as db # Work out a name of the file sFile_path = "Logs/db_read.txt" eDb_read = open(sFile_path, "w", encoding="utf-8") # Read all the geographic data if False: # Do the query xParam = { "aDemand_workforce.aItemised.sName": "wheat farm" } # All queries xRestr = {"_id": 0, "geo_code": 1, "aDemand_workforce.aItemised": 1} ccTremb = db.connect() cDb_of_choice = db.destinations(ccTremb) dQuery = cDb_of_choice.find(xParam, xRestr) # Read data in chronographic order if False: # Do the query xParam = {} # All queries xRestr = {"_id": 1, "my_id": 1, "host_geo_code": 1} ccTremb = db.connect() cDb_of_choice = db.housing(ccTremb) dQuery = cDb_of_choice.find(xParam, xRestr) dQuery = dQuery.distinct("host_geo_code") # Pulls out single element dQuery.sort() # Sort modifies in place. Returns 'none' # Read all the data if True: # Do the query xParam = {} # All queries xRestr = {"_id": 0} ccTremb = db.connect() cDb_of_choice = db.maps_db(ccTremb) dQuery = cDb_of_choice.find(xParam, xRestr) for x in dQuery: print(x) eDb_read.write("{0}\n".format(x)) eDb_read.close()
def mm_star(): """ Tests a concept (This is a scratch pad, or a place to fix mistakes) """ import modules.x_database as db # Delete a single entry if False: xParam = {"dVal.id": 115} xRestr = {} ccTremb = db.connect() cDatabase = db.lines(ccTremb) dQuery = cDatabase.delete_one(xParam, xRestr) print("Specified element deleted") # Delete an entire collection if False: ccTremb = db.connect() cRnd_man = db.rnd_suffix_surname(ccTremb) dQuery = cRnd_man.delete_many({}) print(dQuery.deleted_count, " deleted items!") # Update an array if False: xParam = {"geo_code": "TJV"} # Vaenesston district xNew_data = { "$set": { "aChildren": [ "D00-09I", "D00-09J", "D00-0CM", "D00-0CN", "D00-0CO", ] } } # Prepare the update ccTremb = db.connect() cDest = db.destinations(ccTremb) dParent_query = cDest.update_one(xParam, xNew_data) # Update a bad complex value if False: dNew_data = { 'resource': 'chicken', 'annual_output': 15356, 'units': 't/yr' } xParam = {"my_id": "D00-017"} xNew_data = {"$set": {"aWarehouse.chicken farm 0": dNew_data}} ccTremb = db.connect() cDb = db.destinations(ccTremb) dQuery = cDb.update_one(xParam, xNew_data) # Delete all the geo-codes if False: parent_my_id = "D00-0AL" # Edit me. # Data base connection and selection ccTremb = db.connect() cDb = db.destinations(ccTremb) # Get the parent so we can access the children xParam = {"my_id": parent_my_id} xRestr = {"_id": 0, "aChildren": 1} dQuery = cDb.find(xParam, xRestr) # Analyse the query aChildren = [] for query in dQuery: aChildren = query["aChildren"] # copy out # Erase each child's geo-code for child in aChildren: xParam = {"my_id": child} xNew_data = {"$set": {"geo_code": None}} dQuery = cDb.update_one(xParam, xNew_data) # Global change to the structure if False: dNew_data = { "total": { "rm": 0, "rf": 0, "hm": 0, "hf": 0, "mm": 0, "mf": 0, "lm": 0, "lf": 0, "pm": 0, "pf": 0 }, "aItemised": [], } xParam = {} xNew_data = {"$set": {"aSupply_workforce": dNew_data}} ccTremb = db.connect() cDb = db.destinations(ccTremb) dQuery = cDb.update_many(xParam, xNew_data) # Update a bad simple value if False: dNew_data = "Fusþton" xParam = {'sRegion': 'Loggers Crossing'} # xNew_data = {"$set": {"aVehicles.aItemised.Blàhim" : dNew_data}} xNew_data = {"$set": {'sRegion': dNew_data}} ccTremb = db.connect() cDb = db.maps_db(ccTremb) dQuery = cDb.update_one(xParam, xNew_data) # dQuery = cDb.update_many(xParam, xNew_data) # delete an element if False: xParam = {"geo_code": "GYG"} xNew_data = {"$unset": {"aDemogfx_item": 0, "aWhs_item": 0}} ccTremb = db.connect() cDb = db.destinations(ccTremb) dQuery = cDb.update_one(xParam, xNew_data) # Oblitorate everything except the name, children, area data. # Basically, erase balancing when it was not required. if False: xParam = {"geo_code": "VXA-J"} # Vaenesston district xNew_data = { "$set": { # 'aMap': { # 'sRegion': 'Vænesston', # 'iYear': '2019', # 'fScale': 2000000.0, # 'x': None,'y': None,'a': None}, "aDemand_workforce": { "total": { "rm": 0, "rf": 0, "hm": 0, "hf": 0, "mm": 0, "mf": 0, "lm": 0, "lf": 0, "pm": 0, "pf": 0 }, "aItemised": [] }, "aSupply_workforce": { "total": { "rm": 0, "rf": 0, "hm": 0, "hf": 0, "mm": 0, "mf": 0, "lm": 0, "lf": 0, "pm": 0, "pf": 0 }, "aItemised": [] }, "aDemand_hholds": { "total": { "r": 0, "h": 0, "m": 0, "l": 0, "p": 0 }, "aItemised": [] }, "aSupply_hholds": { "total": { "r": 0, "h": 0, "m": 0, "l": 0, "p": 0 }, "aItemised": [] }, "aDemographics": {}, "aVehicles": {}, "aFootprint": {}, "aWarehouse": {} } } # Prepare the update ccTremb = db.connect() cDest = db.destinations(ccTremb) dParent_query = cDest.update_one(xParam, xNew_data)
def add_station(ccTremb): """ Adds details of a station to the database """ # Obtain the highest "my_id" code that is registered in the database. # Get a list of all the registered base-36 codes xParam = {} xRestr = {"_id": 0, "my_id": 1} cStation = db.stations(ccTremb) dId_query = cStation.find(xParam, xRestr) iHighest, aEvery_id = misc.find_highest_id(dId_query) if (False): # Debugging sTxt = "\n\nHighest number is {0}(10) < < < < < < < <" print(sTxt.format(iHighest)) # We do have the highest identifier (expressed as a decimal number). Hence, # we can incerement the sequence and use it. iNext_id = iHighest + 1 if iNext_id > 36**5: print("\n\aMaximum count has been exceeded") return None # Convert to base36 sBase36 = misc.base_conv(iNext_id) sBase36_5 = sBase36.rjust(5, "0") # "0002W" -> "D00-02W" sNew_id = "S{0}-{1}".format(sBase36_5[:2], sBase36_5[2:]) # START GETTING THE USER TO ENTER THE NEW DATA. # Open a blank dictionary, so that the elements are arranged in a certain # order. dNew_port = { "my_id": sNew_id, "host_geo_code": None, "aName": { "lat": None, "cyr": None }, "type": None, "sub_type": None, "level": None, "aMap": { "sRegion": None, "iYear": None, "fScale": None, "x": None, "y": None, "a": None }, "aArea": { "qty": None, "uom": None }, "lServices": [], "lWarehouse": [], "iLoading_zones": 0, } # HOST cDest = db.destinations(ccTremb) # To verify the geocode sTxt = ("\nWho is hosting this station/port? Please enter thier geo-code.") print(sTxt) sGeo_code = input().upper() aHost_name = misc.verify_geo_code(sGeo_code, cDest) if aHost_name == None: return dNew_port["host_geo_code"] = sGeo_code sTxt = "\nHosted by {0} / {1}".format(aHost_name["lat"], aHost_name["cyr"]) print(sTxt) # TYPE sMenu = "\n" sMenu += "What type of a station or port is it?\n" sMenu += "0: Rail\n" sMenu += "1: Road\n" sMenu += "2: Water\n" sMenu += "3: Air\n" iType_option = misc.get_int(sMenu, 3) if iType_option == None: print("\a") return None if iType_option == 0: dNew_port["type"] = "Rail" elif iType_option == 1: dNew_port["type"] = "Road" elif iType_option == 2: dNew_port["type"] = "Water" elif iType_option == 3: dNew_port["type"] = "Air" else: print("\n\aInvalid choice for port type") return # SUB-TYPE sMenu = "\n" sMenu += "What is transported?\n" sMenu += "0: Passangers (PAX)\n" sMenu += "1: Freight (F)\n" sMenu += "2: Livestock (L/S)\n" iType_option = misc.get_int(sMenu, 2) if iType_option == None: print("\a") return None if iType_option == 0: dNew_port["sub_type"] = "Pax" elif iType_option == 1: dNew_port["sub_type"] = "Freight" elif iType_option == 2: dNew_port["sub_type"] = "Livestock" else: print("\n\aInvalid choice for port type") return # LEVEL sMenu = "\n" sMenu += "What level is the station or port on?\n" sMenu += "0: International ['0V9'->'0Q1']\n" sMenu += "1: National / Inter-Provincial ['V'->'L']\n" sMenu += "2: Provincial / Inter-District ['GY'->'VA']\n" sMenu += "3: District / Inter-County ['GYN'->'GY0']\n" sMenu += "4: County / Inter-Municipal ['GYN-2'->GYN-0] \n" sMenu += "5: Municipal / Intra-Municipal ['VAA-0A'->'VAA-0B'])\n" iLevel_option = misc.get_int(sMenu, 5) if iLevel_option == None: print("\a") return None if iLevel_option == 0: dNew_port["level"] = "Int'l" elif iLevel_option == 1: dNew_port["level"] = "Nat'l" elif iLevel_option == 2: dNew_port["level"] = "Prov." elif iLevel_option == 3: dNew_port["level"] = "Dist." elif iLevel_option == 4: dNew_port["level"] = "Cnty." elif iLevel_option == 5: dNew_port["level"] = "Muni." else: print("\n\aInvalid choice for port type") return # MAP REFERENCE # Obtain the reference to the CAD map. The maps available have their own # database entry cMaps = db.maps_db(ccTremb) xParam = {} xRestr = {"_id": 0} dMap_query = cMaps.find(xParam, xRestr) iNo_of_maps = 0 dMap_copy = [] for dMap in dMap_query: iNo_of_maps += 1 dMap_copy.append(dMap) # Setup a menu of the maps available # Setup an option of entering a region which is not mapped print("\nOn which map is this station/port?") sMenu = "0: No map\n" iCnt = 0 # Go through all the available maps. for one_map in dMap_copy: iCnt += 1 # xScale = "{:.1e}".format(one_map["fScale"]) # 1.0e6 for 1:1M xScale = "{0:,}".format(int(one_map["fScale"])) # Commas every 1000's sTxt = "{0}: {1}, {2} 1:{3}\n" sMenu += sTxt.format(iCnt, one_map["sRegion"], one_map["iYear"], xScale) sMenu += "x: Invalid choice will exit this sub menu" print(sMenu) # Get the response from the user, with reference to the menu being offered. sInput = input() if sInput.isnumeric() == False: # An inbuilt 'abort' system where the user can enter 'x' to exit. print("\nInput is not a numeric value. Returning to menu") return None # Get the details from the dictionary and write them into the destinations # entry. iInput = int(sInput) if (iInput == 0): dNew_port["aMap"]["sRegion"] = "No Map" dNew_port["aMap"]["iYear"] = None dNew_port["aMap"]["fScale"] = None elif (iInput > iCnt): print("\nChoice out of range. Returning to menu") return None else: iIdx = iInput - 1 dNew_port["aMap"]["sRegion"] = dMap_copy[iIdx]["sRegion"] dNew_port["aMap"]["iYear"] = dMap_copy[iIdx]["iYear"] dNew_port["aMap"]["fScale"] = dMap_copy[iIdx]["fScale"] # Map location: Co-ordinates on the speciied CAD map. if (dNew_port["aMap"]["fScale"] != None): # This only works if the map exists. sQuestion = "\nEnter the x-coordinate from the map:" fX = misc.get_float(sQuestion, None, True) if fX == None: return None dNew_port["aMap"]["x"] = fX sQuestion = "\nEnter the y-coordinate from the map:" fY = misc.get_float(sQuestion, None, True) if fY == None: return None dNew_port["aMap"]["y"] = fY sQuestion = "\nEnter the area in mm2 from the map:" fA = misc.get_float(sQuestion) if fA == None: return None dNew_port["aMap"]["a"] = fA # Calcluate the area. dArea = misc.calc_area(dNew_port["aMap"]["a"], dNew_port["aMap"]["fScale"]) if dArea == None: return None # Compensate for inconsistency dArea_2 = {"val": dArea["qty"], "uom": dArea["uom"]} dNew_port["aArea"] = dArea_2 # End of map location entry # NAME IT! bExit = False while bExit == False: sMenu = "\nDo you want a to use host's name/a random name?" sRand_name_yn = misc.get_binary(sMenu) if sRand_name_yn == None: return None sName_only_lat = "" sName_only_cyr = "" # Manual entry: if sRand_name_yn == "N": print("\nPlease enter the name of the station / port in" + "(Use international Keyboard)") sName_only_lat = input() # User entered name in Cyrillic print("\nНапиш име стацйи люб порту в Цырполюю. " + "(пшэлаьч клавятурэ рэьчне)") sName_only_cyr = input() # Randomly generated Name elif sRand_name_yn == "Y": # Operated by an external routine import modules.x_random_names as rnd_name # We are storing the random names from the various systems here. # Hence, we will build up one set of arrays for the user to #choose aLat = [] aCyr = [] # Host name aLat.append(aHost_name["lat"]) aCyr.append(aHost_name["cyr"]) # Male-static: iNo_of_combos = 3 aName = rnd_name.rnd_male_name(iNo_of_combos) aSurname = rnd_name.qRnd_static_surname(iNo_of_combos) for iIdx in range(iNo_of_combos): sName = aName[iIdx]["lat"] sSurname = aSurname[iIdx]["lat"] aLat.append("{0} {1}".format(sName, sSurname)) sName = aName[iIdx]["cyr"] sSurname = aSurname[iIdx]["cyr"] aCyr.append("{0} {1}".format(sName, sSurname)) # Male-dynamic: iNo_of_combos = 3 aName = rnd_name.rnd_male_name(iNo_of_combos) aSurname = rnd_name.qRnd_dynamic_surname(iNo_of_combos) for iIdx in range(iNo_of_combos): sName = aName[iIdx]["lat"] sSurname = aSurname[iIdx]["lat"] aLat.append("{0} {1}".format(sName, sSurname)) sName = aName[iIdx]["cyr"] sSurname = aSurname[iIdx]["cyr"] aCyr.append("{0} {1}".format(sName, sSurname)) # Female-static: iNo_of_combos = 3 aName = rnd_name.rnd_female_name(iNo_of_combos) aSurname = rnd_name.qRnd_static_surname(iNo_of_combos) for iIdx in range(iNo_of_combos): sName = aName[iIdx]["lat"] sSurname = aSurname[iIdx]["lat"] aLat.append("{0} {1}".format(sName, sSurname)) sName = aName[iIdx]["cyr"] sSurname = aSurname[iIdx]["cyr"] aCyr.append("{0} {1}".format(sName, sSurname)) # Female-dynamic: iNo_of_combos = 3 aName = rnd_name.rnd_female_name(iNo_of_combos) aSurname = rnd_name.qRnd_dynamic_surname(iNo_of_combos) for iIdx in range(iNo_of_combos): sName = aName[iIdx]["lat"] sSurname = aSurname[iIdx]["lat"] aLat.append("{0} {1}".format(sName, sSurname)) sName = aName[iIdx]["cyr"] sSurname = aSurname[iIdx]["cyr"] aCyr.append("{0} {1}".format(sName, sSurname)) # Display the names iNo_of_names = len(aLat) sChoices = "0: Choose again\n" # Don't like the options iCnt = 1 for idx in range(0, iNo_of_names): sTxt = "{0}: {1} / {2}\n" sChoices += sTxt.format(iCnt, aLat[idx], aCyr[idx]) iCnt += 1 iChoice = misc.get_int(sChoices, iNo_of_names) if iChoice == None: return None # Invalid choice if iChoice == 0: continue # Choose again. iChoice -= 1 # Export the final names sName_only_lat = aLat[iChoice] sName_only_cyr = aCyr[iChoice] # Prepare post-fix sLat_Intl = "" sCyr_Intl = "" if dNew_port["level"] == "Int'l": sLat_Intl = "International" # The joys of Slavic grammar! if dNew_port["type"] in ["Rail"]: sCyr_Intl = "Меьдзыщнародова" elif dNew_port["type"] in ["Water", "Road"]: sCyr_Intl = "Меьдзыщнародовы" elif dNew_port["type"] in ["Air"]: sCyr_Intl = "Меьдзыщнародовэ" # Type of transport sLat_B = "" sCyr_B = "" # Rail #################################################### if dNew_port["type"] == "Rail": if dNew_port["sub_type"] == "Pax": sLat_B = "Train Station" sCyr_B = "Стаця Колеёва" elif dNew_port["sub_type"] == "Freight": sLat_B = "Freight Station" sCyr_B = "Стаця Товарова" elif dNew_port["sub_type"] == "Livestock": sLat_B = "Livestock Station" sCyr_B = "Стаця Звъежаьт" # Road - - - - - - - - - - - - - - - - - - - - - - - - - - - elif dNew_port["type"] == "Road": if dNew_port["sub_type"] == "Pax": sLat_B = "Bus Station" sCyr_B = "Двожэс Алтобусовы" elif dNew_port["sub_type"] == "Freight": sLat_B = "Truck Depot" sCyr_B = "Двожэс Товаровы" elif dNew_port["sub_type"] == "Livestock": sLat_B = "Livestock Depo" sCyr_B = "Двожэс Звъежэьтьи" # Water ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ elif dNew_port["type"] == "Water": if dNew_port["sub_type"] == "Pax": sLat_B = "Passanger Harbour" sCyr_B = "Порт Особовы" elif dNew_port["sub_type"] == "Freight": sLat_B = "Freight Harbour" sCyr_B = "Порт Товаровы" elif dNew_port["sub_type"] == "Livestock": sLat_B = "Livestock Harbour" sCyr_B = "Порт Звъежэьтьи" # Air > > > - - - - - - - - - - - - - - - - - < < < elif dNew_port["type"] == "Air": if dNew_port["sub_type"] == "Pax": sLat_B = "Airport" sCyr_B = "Лётниско" elif dNew_port["sub_type"] == "Freight": sLat_B = "Freight Airport" sCyr_B = "Лётниско Товаровэ" elif dNew_port["sub_type"] == "Livestock": sLat_B = "Livestock Airport" sCyr_B = "Лётниско Звъежэьцэ" else: print("Invalid choice. Exiting") return None # Full Latin name if sLat_Intl == "": sTxt = "{0} {1}".format(sName_only_lat, sLat_B) else: sTxt = "{0} {1} {2}".format(sName_only_lat, sLat_Intl, sLat_B) dNew_port["aName"]["lat"] = sTxt # Cyrillc grammar if sCyr_Intl == "": sTxt = "{1} о им. {0}".format(sName_only_cyr, sCyr_B) else: sTxt = "{1} {2} о им. {0}" sTxt = sTxt.format(sName_only_cyr, sCyr_Intl, sCyr_B) dNew_port["aName"]["cyr"] = sTxt # Confirm the name choice sNew_lat = dNew_port["aName"]["lat"] sNew_cyr = dNew_port["aName"]["cyr"] sMenu = "Are the names:\n'{0}'\n'{1}' OK?" sMenu = sMenu.format(sNew_lat, sNew_cyr) sNames_ok_yn = misc.get_binary(sMenu) if sNames_ok_yn == "Y": bExit = True # End of 'its named' # SERVICES: WHICH AREA DOES THIS FACILITY SERVICE bDone = False # Multiple areas. while bDone == False: sTxt = ( "\nThis station/port serves the people of ___." + "\n(Enter the geo-code of the entity OR Press '.' to exit loop") print(sTxt) sGeo_code = input().upper() if sGeo_code in ["", None, "."]: bDone = True continue # Verify the geo-code aName = misc.verify_geo_code(sGeo_code, cDest) if aName == None: bDone = True continue # Geocode verified, add the geo code to the list dNew_port["lServices"].append(sGeo_code) sLat_name = aName["lat"] sCyr_name = aName["cyr"] print("({0} / {1})".format(sLat_name, sCyr_name)) # end of while loop # WAREHOUSE: lSta_Whs = dNew_port["lWarehouse"] # Station warehouse for sTown in dNew_port["lServices"]: # Passanger or freight? if dNew_port["sub_type"] == "Pax": aData = {} # Travel demand: Why not model on Newton's equation of gravitation: # F = G*m1*m2 / r^2. Where, 'm' would be the population. xParam = {"geo_code": sTown} xRestr = {"_id": 0, "aDemographics": 1} dRun_query = cDest.find(xParam, xRestr) for query in dRun_query: aData = query["aDemographics"] # Freight or livestock: else: # Pull the data from the warehouses. dClt_whs = [] # List, client warehouse xParam = {"geo_code": sTown} xRestr = {"_id": 0, "aWarehouse": 1} dRun_query = cDest.find(xParam, xRestr) for query in dRun_query: dClt_whs = query["aWarehouse"] # The could be no data in the warehouse if dClt_whs == {}: continue # Extract the data from the warehouse for sShelf in dClt_whs: # Pull the data apart: look what is on the 'shelf' dContent = dClt_whs[sShelf] sResource = dContent["resource"].lower() fAmount = dContent["annual_output"] xUnits = dContent["units"] if xUnits == "t/yr": xUnits = "t/wk" elif xUnits == "kg/yr": xUnits = "kg/wk" elif xUnits == "kt/yr": xUnits = "kt/wk" else: print("Units are not presented as weight per year") # We have "shelves" in the warehouse already bNot_found = True for dSta_whs_shelf in lSta_Whs: # Find the correct shelf to add the contents. if dSta_whs_shelf["resource"] != sResource: continue if dSta_whs_shelf["units"] != xUnits: print("\n\aUnits mismatch at the warehouse. EXITING") return None fWeekly_produce = round(fAmount / 52, 2) fWeekly_total = dSta_whs_shelf["weekly_output"] fSub_tot = round(fWeekly_total + fWeekly_produce, 2) dSta_whs_shelf["weekly_output"] = fSub_tot bNot_found = False # We need to add another shelf to the warehouse: if bNot_found == True: dEntry = {} dEntry["resource"] = sResource # NOTE: Logistics run on weekly cycles. dEntry["weekly_output"] = round(fAmount / 52, 2) dEntry["units"] = xUnits lSta_Whs.append(dEntry) # End of warehouse shelf created # end of going through each of the client's shelves # end of freight/livestock vs passangers # end of going through the towns on the include list. fTot_weight = 0.0 for dEntry in dNew_port["lWarehouse"]: sName = dEntry["resource"] fAmount = dEntry["weekly_output"] sUnits = dEntry["units"] if sUnits == "t/wk": fTot_weight += fAmount # Publish total weight elif sUnits == "kt/wk": fTot_weight += fAmount * 1000 elif sUnits == "kg/wk": fTot_weight += fAmount / 1000 sTxt = "{0}: {1}{2}".format(sName, fAmount, sUnits) print(sTxt) if len(dNew_port["lWarehouse"]) > 0: fTot_weight = round(fTot_weight, 3) # Round off . fTot_daily = fTot_weight / 5.0 # MON to FRI fTot_daily = round(fTot_daily, 3) sTxt = "-------------\n" sTxt += "TOTAL: {0}t/wk\n".format(fTot_weight) sTxt += "TOTAL: {0}t/day\n".format(fTot_daily) print(sTxt) # Number of loading bays sTxt = ("\nEnter the number of 'loading zones'. " + "Take into account the imports") iLoading_zones = misc.get_int(sTxt) if iLoading_zones == None: return dNew_port["iLoading_zones"] = iLoading_zones # ATTACH TO HOST if dNew_port["type"] == "Rail": if dNew_port["sub_type"] == "Pax": sInd_code = "QP1" # Passanger operations else: # Freight / livestock operations sInd_code = "QF1" # ROAD TRANSPORT elif dNew_port["type"] == "Road": if dNew_port["sub_type"] == "Pax": sInd_code = "QB1" # Bus operations else: sInd_code = "QT1" # Truck port. Currently at 20t / trip # Air TRANSPORT elif dNew_port["type"] == "Air": if dNew_port["sub_type"] == "Pax": sInd_code = "QA1" # Passanger air ops else: sInd_code = "QG1" # Freight air ops dBriefcase = { "ccTremb": ccTremb, # Link to all the databases "sGeo_code": dNew_port["host_geo_code"], # of the host "sInd_code": sInd_code, # Passanger or Freight? "sName_lat": dNew_port["aName"]["lat"], # Don't overkill it. "sYour_id": dNew_port["my_id"], # When constructed in city, link it! "aArea": dNew_port["aArea"], # Footprint "iNo_of_builds": 1, # Number of stations. "lServices": dNew_port["lServices"], # Who makes use of this? "fCapacity": None, # How much is used (schools, ect) } xFeedback = d_py.add_wkp_auto(dBriefcase) if xFeedback == None: return cStation.insert_one(dNew_port) print("\n>>>\nNew station added")
def get_map_input(ccTremb, sMap="item"): """ Method asks the user to select the map and enter the co-ordinates of the object of interest into the database. Common to 'D', 'H', 'S'. """ import modules.x_database as db # Obtain the reference to the CAD map. The maps available have their own # database entry cMaps = db.maps_db(ccTremb) xParam = {} xRestr = {"_id": 0} dMap_query = cMaps.find(xParam, xRestr) iNo_of_maps = 0 dMap_copy = [] for dMap in dMap_query: iNo_of_maps += 1 dMap_copy.append(dMap) # Setup a menu of the maps available # Setup an option of entering a region which is not mapped print("\nOn which map is this '{0}'?".format(sMap)) sMenu = "0: No map\n" iCnt = 0 # Go through all the available maps. for one_map in dMap_copy: iCnt += 1 # xScale = "{:.1e}".format(one_map["fScale"]) # 1.0e6 for 1:1M xScale = "{0:,}".format(int(one_map["fScale"])) # Commas every 1000's sTxt = "{0}: {1}, {2} 1:{3}\n" sMenu += sTxt.format(iCnt, one_map["sRegion"], one_map["iYear"], xScale) sMenu += "x: Invalid choice will exit this sub menu" print(sMenu) # Get the response from the user, with reference to the menu being offered. sInput = input() if sInput.isnumeric() == False: # An inbuilt 'abort' system where the user can enter 'x' to exit. print("\n\aInput is not a numeric value. Returning to menu") return None # Get the details from the dictionary and write them into the destinations # entry. iInput = int(sInput) dMap = {} if (iInput == 0): dMap["sRegion"] = "No Map" dMap["iYear"] = None dMap["fScale"] = None dMap["x"] = None dMap["y"] = None dMap["a"] = None return True elif (iInput > iCnt): print("\nChoice out of range. Returning to menu") return None else: iIdx = iInput - 1 dMap["sRegion"] = dMap_copy[iIdx]["sRegion"] dMap["iYear"] = dMap_copy[iIdx]["iYear"] dMap["fScale"] = dMap_copy[iIdx]["fScale"] # Map location: Co-ordinates on the speciied CAD map. if (dMap["fScale"] != None): # This only works if the map exists. sQuestion = "\nEnter the x-coordinate from the map:" fX = get_float(sQuestion, None, True) if fX == None: return None dMap["x"] = fX sQuestion = "\nEnter the y-coordinate from the map:" fY = get_float(sQuestion, None, True) if fY == None: return None dMap["y"] = fY sQuestion = "\nEnter the area in mm2 from the map{0}:".format(sMap) fA = get_float(sQuestion) if fA == None: return None dMap["a"] = fA # Calcluate the area. dArea = calc_area(dMap["a"], dMap["fScale"]) if dArea == None: return None # Compensate for inconsistency dArea_2 = {"val": dArea["qty"], "uom": dArea["uom"]} # End of map location entry dReturn = { "dMap": dMap, "dArea": dArea_2, } return dReturn