def forecast(self, sku: str) -> tuple: """Forecast state. Args: sku (str): SKU unique identification number Returns: tuple: """ # if the demand shows a linear trend then check if the forecast is less than the excess units. if self._htces_forecast.get(sku)['statistics']['trend']: if self._htces_forecast.get(sku)['forecast'][0] < int(self._summary.get('excess_units')): response = 'It is unlikely {} will fair better next month as the most optimistic forecast is ' self.append_response(response=response, sku=sku) if self._htces_forecast.get(sku)['statistics']['trend'] and int(self._summary.get('excess_units')) > 0 \ and self._summary.get('classification') in ('AX', 'AY', 'BX', 'BY', 'CX') \ and self._htces_forecast.get(sku)['forecast'][0] > int(self._summary.get('excess_units')): response = 'The current excess can be reduced by reducing purchase orders and allow the ' \ 'forecasted demand to be catered for from stock. ' self.append_response(response=response, sku=sku) state = self._TRANSITION_STATES.get('RECOMMENDATION_STATE', self._END_STATE) serialise_config(configuration=self._compiled_response.shared_response, file_path=ABS_FILE_PATH['RECOMMENDATION_PICKLE']) return state, sku
def inventory_turns(self, sku: str = None) -> str: """ Inventory turns state. Args: sku (str): SKU unique identification. Returns: str: New state """ skus = [i.sku_id for i in self.analysed_orders] sku_inventory_turns = {skus[index]: description.get('inventory_turns') for index, description in enumerate(self.summarised_inventory.describe_sku(*skus))} sku_unit_cost = {skus[index]: description.get('unit_cost') for index, description in enumerate(self.summarised_inventory.describe_sku(*skus))} slow_turners = heapq.nsmallest(5, sku_inventory_turns, key=lambda s: sku_inventory_turns[s]) expensive_stock = heapq.nlargest(5, sku_unit_cost, key=lambda s: sku_inventory_turns[s]) slow_turning_expensive_stock = [sku for sku in slow_turners if sku in expensive_stock] if len(slow_turning_expensive_stock) > 0: response = '{sku} experience the slowest inventory turns in the inventory profile, while simultaneously ' \ 'being the most costly items.' self.append_response(response=response, sku=sku) serialise_config(configuration=self._compiled_response.shared_response, file_path=ABS_FILE_PATH['PROFILE_PICKLE']) state = self._TRANSITION_STATES.get('RECOMMENDATION_STATE', self._END_STATE) return state
def run(self): config = deserialise_config(ABS_FILE_PATH_APPLICATION_CONFIG) config['port'] = self.port config['host'] = self.host serialise_config(config, ABS_FILE_PATH_APPLICATION_CONFIG) # print(self.port) app.run(host= self.host,port=self.port)
def run(self): config = deserialise_config(ABS_FILE_PATH_APPLICATION_CONFIG) config['port'] = self.port config['host'] = self.host serialise_config(config, ABS_FILE_PATH_APPLICATION_CONFIG) # print(self.port) self.app.run(host=self.host, port=int(self.port))
def _os_specific_uri(action_case: str, my_os: list, type_case: str) -> str: """ Constructs os specific uri. Args: action_case: The action base indicates wheter the connection is for retrieving from or creating a database my_os: The os the user is running the library on. type_case: Indicates wether the uri is for the csv management database or the reporting database Returns: """ app_config = deserialise_config(ABS_FILE_PATH_APPLICATION_CONFIG) man_config = deserialise_config(ABS_FILE_PATH_CSV_MANAGEMENT_CONFIG) db_uri = '' unix, windows = [case['POSIX'], case['MACINTOSH']], [case['NT']] if action_case == case['RETRIEVAL'] and type_case == case['REPORTING']: if os.name in unix: db_uri = 'sqlite:///{}/reporting.db'.format( app_config['database_path']) elif os.name in windows: db_uri = 'sqlite:///{}\\reporting.db'.format( app_config['database_path']) return db_uri elif action_case == case['RETRIEVAL'] and type_case == case['MANAGEMENT']: if os.name in unix: db_uri = 'sqlite:///{}/{}'.format(man_config['database_path'], man_config['database_name']) elif os.name in windows: db_uri = 'sqlite:///{}\\{}'.format(man_config['database_path'], man_config['database_name']) return db_uri elif action_case == case['CREATE'] and type_case == case['MANAGEMENT']: database_name = 'csv_management-{}.db'.format(uuid.uuid1()) if os.name in unix: db_uri = 'sqlite:///{}/{}'.format(ABS_FILE_PATH_ARCHIVE, database_name) elif os.name in windows: db_uri = 'sqlite:///{}\\{}'.format(ABS_FILE_PATH_ARCHIVE, database_name) config = { 'database_path': ABS_FILE_PATH_ARCHIVE, 'database_name': database_name, 'database_connection': db_uri } serialise_config(configuration=config, file_path=ABS_FILE_PATH_CSV_MANAGEMENT_CONFIG) return db_uri
def _os_specific_uri(action_case: str, my_os: list, type_case: str) -> str: """ Constructs os specific uri. Args: action_case: The action base indicates wheter the connection is for retrieving from or creating a database my_os: The os the user is running the library on. type_case: Indicates wether the uri is for the csv management database or the reporting database Returns: """ app_config = deserialise_config(ABS_FILE_PATH_APPLICATION_CONFIG) man_config = deserialise_config(ABS_FILE_PATH_CSV_MANAGEMENT_CONFIG) db_uri = '' unix, windows = [case['POSIX'], case['MACINTOSH']], [case['NT']] if action_case == case['RETRIEVAL'] and type_case == case['REPORTING']: if os.name in unix: db_uri = 'sqlite:///{}/reporting.db'.format(app_config['database_path']) elif os.name in windows: db_uri = 'sqlite:///{}\\reporting.db'.format(app_config['database_path']) return db_uri elif action_case == case['RETRIEVAL'] and type_case == case['MANAGEMENT']: if os.name in unix: db_uri = 'sqlite:///{}/{}'.format(man_config['database_path'], man_config['database_name']) elif os.name in windows: db_uri = 'sqlite:///{}\\{}'.format(man_config['database_path'], man_config['database_name']) return db_uri elif action_case == case['CREATE'] and type_case == case['MANAGEMENT']: database_name = 'csv_management-{}.db'.format(uuid.uuid1()) if os.name in unix: db_uri = 'sqlite:///{}/{}'.format(ABS_FILE_PATH_ARCHIVE, database_name) elif os.name in windows: db_uri = 'sqlite:///{}\\{}'.format(ABS_FILE_PATH_ARCHIVE, database_name) config = { 'database_path': ABS_FILE_PATH_ARCHIVE, 'database_name': database_name, 'database_connection': db_uri } serialise_config(configuration=config, file_path=ABS_FILE_PATH_CSV_MANAGEMENT_CONFIG) return db_uri
def setUp(self): app = Flask(__name__, instance_relative_config=True) PWD = os.path.abspath(os.curdir) i_c = IntegrationConfig i_c.SQLALCHEMY_DATABASE_URI = 'sqlite:///{}/reporting.db'.format(PWD) app.config.from_object(i_c) app.config['DATABASE'] = PWD app.config['TESTING'] = True self.app = app.test_client() self._file = ABS_FILE_PATH['COMPLETE_CSV_SM'] app_settings = { 'file': self._file, 'currency': 'USD', 'database_path': PWD, } serialise_config(app_settings, ABS_FILE_PATH_APPLICATION_CONFIG) with app.app_context(): db.init_app(app) db.create_all()
def copy_file(): """Copies file used to load analysis and stores in archive folder for posterity. Returns: """ # Retrieve file_name and path to the source data csv config_file = deserialise_config(ABS_FILE_PATH_APPLICATION_CONFIG) file_name = config_file.get('file', 'UNKNOWN') file_path = config_file.get('database_path', 'UNKNOWN') print(file_path, file_name) if 'UNKNOWN' not in (file_path, file_name): try: # Copy data source file to archive copyfile('{}{}'.format(file_path, file_name), '{}/{}-{}.csv'.format(ABS_FILE_PATH_ARCHIVE, 'data_file', uuid.uuid1())) config_file['file_path'] = '{}/{}-{}.csv'.format(ABS_FILE_PATH_ARCHIVE, 'data_file', uuid.uuid1()) serialise_config(config_file, ABS_FILE_PATH_APPLICATION_CONFIG) except FileExistsError as e: print('The source file is not in the same location as the analysis database. Please place the file in ' 'the same location and restart the process.')
def main(): parser = argparse.ArgumentParser( description='Supplychainpy commandline interface a') parser.add_argument(dest='filenames', metavar='filename', nargs='?') parser.add_argument( '-l', '--launch', dest='launch', action='store_true', help='Launches supplychainpy reporting gui for setting \ port and launching the default browser.') parser.add_argument( '-lx', '--launch-console', dest='launch_console', action='store_true', help='Launches supplychainpy reporting in the default browser, \ without gui interface. Uses default port (5000) unless another port \ is specified. ') parser.add_argument( '-a', '--analyse', dest='analyse_file', action='store_true', help='Processes the file supplied as the first argument \ and performs analysis') parser.add_argument('-o', dest='outfile', action='store', help='output file') parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help='verbose mode') parser.add_argument('-db', dest='database', action='store', help='database engine uri e.g. ') parser.add_argument( '-cur', dest='currency', action='store', help='Sets the currency for the analysis. The currency should \ match the currency of the raw data. IMPORTANT: Currency \ conversion does not occur by setting this flag. The default \ currency is US Dollars (USD). ', default='USD') parser.add_argument('--host', dest='host', action='store', help='Sets the host for the server \ (defaults 127.0.0.1) ', default='127.0.0.1') parser.add_argument('--debug', dest='debug', action='store_true', help='Runs in debug mode (default : debug.INFO)') parser.add_argument('-loc', dest='location', action='store', help='database path e.g. ') parser.add_argument('-u', dest='user', action='store', help='user name ') parser.add_argument('-p', '--port', dest='port', action='store', help='port to use for local server e.g. 8080 \ (default: 5000)', default='5000') parser.add_argument('-c', dest='chat', action='store_true', help='chat to dash from the command line') args = parser.parse_args() if args.verbose: print('filenames = {}'.format(args.filenames)) print('launch reports = {}'.format(args.launch)) print('process file = {}'.format(args.analyse_file)) print('database location = {}'.format(args.location)) if args.debug: logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') if args.launch and args.analyse_file is None and args.filenames is not None and args.location: # -l -loc print(1) if args.currency is not None: currency = args.currency else: currency = 'USD' app_settings = deserialise_config(ABS_FILE_PATH_APPLICATION_CONFIG) app_settings['database_path'] = args.location app_settings['file'] = args.filenames app_settings['currency'] = currency serialise_config(app_settings, ABS_FILE_PATH_APPLICATION_CONFIG) #d = _Orchestrate() #d.copy_file() #db_present = d.check_for_db() #if db_present: # create_management_db() launch_load_report(args.filenames, args.location) elif args.launch and args.analyse_file and args.filenames is not None and args.location is not None: # -a -loc -l print(2) if args.currency is not None: currency = args.currency else: currency = 'USD' app_settings = deserialise_config(ABS_FILE_PATH_APPLICATION_CONFIG) app_settings['database_path'] = args.location app_settings['file'] = args.filenames app_settings['currency'] = currency serialise_config(app_settings, ABS_FILE_PATH_APPLICATION_CONFIG) #d = _Orchestrate() #d.copy_file() #db_present = d.check_for_db() #if db_present: # create_management_db() launch_load_report(args.filenames, args.location) elif args.launch and args.location is not None and args.host: # -l -loc --host print(3) app_settings = deserialise_config(ABS_FILE_PATH_APPLICATION_CONFIG) app_settings['database_path'] = args.location app_settings['port'] = args.port serialise_config(app_settings, ABS_FILE_PATH_APPLICATION_CONFIG) launch_report(location=args.location, host=args.host, port=args.port) elif args.launch and args.analyse_file and args.filenames and args.location: # -a -l -loc print(4) if args.currency is not None: currency = args.currency else: currency = 'USD' app_settings = deserialise_config(ABS_FILE_PATH_APPLICATION_CONFIG) app_settings['database_path'] = args.location app_settings['file'] = args.filenames app_settings['currency'] = currency serialise_config(app_settings, ABS_FILE_PATH_APPLICATION_CONFIG) #d = _Orchestrate() #d.copy_file() #db_present = d.check_for_db() #if db_present: # create_management_db() launch_load_report(args.filenames, args.location) launch_report(location=args.location, host=args.host, port=args.port) elif args.analyse_file and args.location is not None and args.filenames is not None and args.launch_console is None: # -a load_db(file=args.filenames, location=args.location) elif args.analyse_file and args.location and args.filenames and args.launch_console and args.port: # -a -loc --lx -p try: print(5) app_settings = { 'database_path': args.location, 'file': args.filenames, 'currency': args.currency } serialise_config(app_settings, ABS_FILE_PATH_APPLICATION_CONFIG) #d = _Orchestrate() #d.copy_file() #db_present = d.check_for_db() #if db_present: # create_management_db() load_db(file=args.filenames, location=args.location) launch_report_server(location=args.location, port=args.port, host=args.host) except OSError as e: print(e) elif args.location and args.launch_console and args.port and args.host: # -loc -lx -p --host try: print(6) app_settings = { 'database_path': args.location, 'host': args.host, 'currency': args.currency } serialise_config(app_settings, ABS_FILE_PATH_APPLICATION_CONFIG) launch_report_server(location=args.location, port=args.port, host=args.host) except OSError as e: print(e) elif args.analyse_file and args.location is not None and args.filenames is not None and args.launch_console is None and args.host: # -a -loc -lx --host print(7) app_settings = { 'database_path': args.location, 'host': args.host, 'currency': args.currency } serialise_config(app_settings, ABS_FILE_PATH_APPLICATION_CONFIG) launch_report_server(location=args.location, port=args.port, host=args.host) elif args.chat: msg = input("Enter message for Dash: ") while msg != 'q': dash = ChatBot() response = dash.chat_machine(message=msg) for i in response: print('Dash> ', i) msg = input("> ")
def main(): parser = argparse.ArgumentParser(description='Supplychainpy commandline interface a') parser.add_argument(dest='filenames', metavar='filename', nargs='?') parser.add_argument('-l', '--launch', dest='launch', action='store_true', help='Launches supplychainpy reporting gui for setting port and launching the default browser.') parser.add_argument('-lx', '--launch-console', dest='launch_console', action='store_true', help='Launches supplychainpy reporting in the default browser, without gui interface. Uses default port (5000) unless another port is specified. ') parser.add_argument('-a', '--analyse', dest='analyse_file', action='store_true', help='Processes the file supplied as the first argument and performs analysis') parser.add_argument('-o', dest='outfile', action='store', help='output file') parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help='verbose mode') parser.add_argument('-db', dest='database', action='store', help='database engine uri e.g. ') parser.add_argument('-cur', dest='currency', action='store', help='Sets the currency for the analysis. The currency should match the currency of the ' 'raw data. IMPORTANT: Currency conversion does not occur by setting this flag. ' 'The default currency is US Dollars (USD). ', default='USD') parser.add_argument('--host', dest='host', action='store', help='Sets the host for the server (defaults 127.0.0.1) ', default='127.0.0.1') parser.add_argument('-loc', dest='location', action='store', help='database path e.g. ') parser.add_argument('-u', dest='user', action='store', help='user name ') parser.add_argument('-p', '--port', dest='port', action='store', help='port to use for local server e.g. 8080 (default: 5000)', default='5000') args = parser.parse_args() if args.verbose: print('filenames = {}'.format(args.filenames)) print('launch reports = {}'.format(args.launch)) print('process file = {}'.format(args.analyse_file)) print('database location = {}'.format(args.location)) if args.launch and args.analyse_file and args.filenames is not None and args.location is None: print(1) launch_load_report(args.filenames) elif args.launch and args.analyse_file and args.filenames is not None and args.location is not None: print(2) if args.currency is not None: currency= args.currency else: currency = 'USD' app_settings = { 'database_path': args.location, 'file': args.filenames, 'currency': currency } serialise_config(app_settings, ABS_FILE_PATH_APPLICATION_CONFIG) #d = _Orchestrate() #d.copy_file() #db_present = d.check_for_db() #if db_present: # create_management_db() launch_load_report(args.filenames, args.location) elif args.launch and args.location is not None and args.host: print(3) app_settings = { 'database_path': args.location, 'host': args.host, 'currency': args.currency } serialise_config(app_settings, ABS_FILE_PATH_APPLICATION_CONFIG) launch_report(location=args.location, host=args.host, port=args.port) elif args.analyse_file and args.location is not None and args.filenames is not None and args.launch_console is None: print(4) load_db(file=args.filenames, location=args.location) elif args.analyse_file and args.location and args.filenames and args.launch_console and args.port: print(5) app_settings = { 'database_path': args.location, 'file': args.filenames, 'currency': args.currency } serialise_config(app_settings, ABS_FILE_PATH_APPLICATION_CONFIG) #d = _Orchestrate() #d.copy_file() #db_present = d.check_for_db() #if db_present: # create_management_db() load_db(file=args.filenames, location=args.location) launch_report_server(location=args.location,port=args.port, host=args.host) elif args.location and args.launch_console and args.port and args.host: print(6) app_settings = { 'database_path': args.location, 'host': args.host, 'currency': args.currency } serialise_config(app_settings, ABS_FILE_PATH_APPLICATION_CONFIG) launch_report_server(location=args.location,port=args.port, host=args.host)