def sub_menu(): """ Provides lines """ ccTremb = db.connect() cRoad = db.road_routes(ccTremb) sSub_menu = """ LINES SUB-MENU (R): .: Exit 01: New Road (Todo) 11: New Junction (Todo) """ # Go through the menu system. bExit = False while bExit == False: # loop until the user exits print(sSub_menu) sInput = input().upper() # Analise the user choice if sInput == ".": # Exit bExit = True elif sInput == "01": # Open new line add_road(ccTremb) elif sInput == "11": # Open new line add_junction(ccTremb)
def sub_menu(): """ Provides choices for the land mapped in CAD """ ccTremb = db.connect() cStation = db.stations(ccTremb) sSub_menu = """ HOUSING SUB-MENU (H): .: Exit 1: Add a housing 4: Pretty print """ # Closes the multi=line txt bExit = False while bExit == False: # loop until the user exits print(sSub_menu) sInput = input().upper() # User has made their choice. Now, process it. if sInput == ".": # Exit bExit = True elif sInput == "1": # New add_housing(ccTremb) # elif sInput == "2": # All the stations # view_all(ccTremb) # elif sInput == "3": # View single # view_single(ccTremb) elif sInput == "4": # Formats the little bit of data pretty_print_single(ccTremb) else: bExit = True
def sub_menu(): """ Provides choices for the land mapped in CAD """ ccTremb = db.connect() cStation = db.stations(ccTremb) sSub_menu = """ COMMUNITY SERVICES SUB-MENU (A): .: Exit 1: Add a community service 2: View children's demands (tabular) """ # Closes the multi=line txt bExit = False while bExit == False: # loop until the user exits print(sSub_menu) sInput = input().upper() # User has made their choice. Now, process it. if sInput == ".": # Exit bExit = True elif sInput == "1": # New add_community_services(ccTremb) elif sInput == "2": # All the stations view_child_demands(ccTremb) # elif sInput == "3": # View single # view_single(ccTremb) # elif sInput == "4": # Formats the little bit of data # pretty_print_single(ccTremb) else: bExit = True
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 sub_menu(): """ Operates the simulator """ ccTremb = db.connect() sSub_menu = """ SIMULATOR SUB-MENU (O): .: Exit X: Run Experiment (I don't know what I'm doing yet) """ # Go through the menu system. bExit = False while bExit == False: # loop until the user exits print(sSub_menu) sInput = input().upper() # Analise the user choice if sInput == ".": # Exit bExit = True elif sInput == "X": # Open new line calc_timetable(ccTremb)
def mm_fwd_slash(): """ Calculates the paper distance for a desired slope """ import modules.x_misc as misc import modules.x_database as db ccTremb = db.connect() dMap = misc.get_the_map(ccTremb) if dMap == None: print("\n\aInvalid map choice. Returning") return None fScale = dMap["fScale"] # Ask for the desired gradient sTxt = "Enter the desired gradient as 1:x (rail std is 100, highway: 33)" fHoriz_per_Vert = misc.get_float(sTxt) if fHoriz_per_Vert == None: return None # Ask for the elevation change sTxt = "Enter elevation change in feet, don't worry about the sign" fVert_ft = misc.get_float(sTxt) if fVert_ft == None: return None # Do the calculation fVert_m = fVert_ft * 0.3048 fHoriz_m = fVert_m * fHoriz_per_Vert # h = v * h/v (v's cancel) fPaper_m = fHoriz_m / fScale # 2500m @ 1:1M = 0.0025m fPaper_mm = round(fPaper_m * 1000, 2) sAll = "----------------------------\n" sAll += "{0}mm on the map are required\n".format(fPaper_mm) sAll += "----------------------------\n" sAll += "{0}ft(v) = {1:.1f}m(v)\n".format(fVert_ft, fVert_m) sTxt = "{0:.1f}m(h) = {1:.1f}m(v) * {2:.1f}m(h)/m(v)\n" sTxt = sTxt.format(fHoriz_m, fVert_m, fHoriz_per_Vert) sAll += sTxt sTxt = "{0}mm(p) = {1:.1f}m(h) / {2:.1f}m/m(scale)\n" sTxt = sTxt.format(fPaper_mm, fHoriz_m, fScale) sAll += sTxt print(sAll)
def sub_menu(): """ Provides lines """ ccTremb = db.connect() cLine = db.lines(ccTremb) sSub_menu = """ LINES SUB-MENU (K): .: Exit 1: Open New line (Record its meta-data) 3: Pretty print one line (ordered by distance) 4: Pretty print meta data to a file 5: Add to line (Sub-component as a new entry) 6: Do a gradient (elevation change) report C: Calculate distance on map for gradient _: Remove a sub-component from the line """ # Go through the menu system. bExit = False while bExit == False: # loop until the user exits print(sSub_menu) sInput = input().upper() # Analise the user choice if sInput == ".": # Exit bExit = True elif sInput == "1": # Open new line add_line(ccTremb) elif sInput == "3": # Prints the line ordered by km. pretty_print_all(ccTremb) elif sInput == "4": # Meta-data view pretty_print_meta(ccTremb) elif sInput == "5": # New component of a line add_sub_comp(ccTremb) elif sInput == "6": pretty_gradient(ccTremb) elif sInput == "C": design_gradient(ccTremb) elif sInput == "_": remove_sub_comp(ccTremb)
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)