Exemple #1
0
    def calc_best_routes(self):
        c.logging('Begin best route calculation')
        t_best_route_array = []
        t_station_array = []
        i = 0
        # создадим массив для того чтобы были неповторяющиеся отношения
        for system in self.cache_data[c.cd_pr]:
            for station in self.cache_data[c.cd_pr][system]:
                if int((self.cache_data[c.cd_st][system][station])[0]) <= c.station_distance:
                    t_station_array.append({'system': system, 'station': station})
                    i += 1

        # общее кол-во станций в переборе
        i = round(i*i/2)
        print('Общее кол-во станций в переборе: {}'.format(i))
        # для текущего указателя перебора
        y = 0
        # для сохранения текущего прогресса
        z = 0
        # low_system_distance = 0
        # max_system_distance = 30
        print('Построение массива маршрутов: ', end='')
        while len(t_station_array) > 0:
            route_begin = t_station_array.pop()
            for route_end in t_station_array:
                # забыл  проверить на расстояние
                if c.low_system_distance < self.calc_distance(route_begin['system'], route_end['system']) <= c.max_system_distance:
                    t_direct = self.get_in_td(route_begin['system'], route_end['system'], route_begin['station'], route_end['station'])
                    t_reverse = self.get_in_td(route_begin['system'], route_end['system'], route_begin['station'], route_end['station'], 'r')
                    if t_direct['status'] == 1 and t_reverse['status'] == 1:
                        t_best_route_array.append({'direct': t_direct, 'reverse': t_reverse})
                y += 1
                if (round((y/i)*100) % 10) == 0 and round((y/i)*10) != z:
                    z = round((y/i)*10)
                    print('#', end='')
        print()
        t_best_route_array.sort(key = c.best_sort_func, reverse = True)

        c.clear_file(c.output_file_name)
        for route in t_best_route_array:
            with open(c.output_file_name, mode='a') as f:
                f.write('route: {} [{} ls] --> {} [{} ls] ({: >5} ly) profit: {: >5} cr\n'.format(route['direct']['route_begin'], route['direct']['station_a_dist'], route['direct']['route_end'], route['direct']['station_b_dist'], route['direct']['route_dist'], (int(route['direct']['profit']) + int(route['reverse']['profit']))))
                f.write('\t{: <21}: profit {: >5} cr, buy {: >5} cr, sell {: >5} cr, stock {: >9}, demand {: >9}\n'.format(route['direct']['product'], route['direct']['profit'], route['direct']['buy'], route['direct']['sell'], route['direct']['stock'], route['direct']['demand']))
                f.write('\t{: <21}: profit {: >5} cr, buy {: >5} cr, sell {: >5} cr, stock {: >9}, demand {: >9}\n'.format(route['reverse']['product'], route['reverse']['profit'], route['reverse']['buy'], route['reverse']['sell'], route['reverse']['stock'], route['reverse']['demand']))
                f.write('\n')

        c.logging('End best route calculation')
Exemple #2
0
 def __init__(self):
     super(CacheData, self).__init__()
     #
     #c.cd_pr = 'prices'
     #c.cd_sm = 'systems'
     #c.cd_st = 'stations'
     #cd_stsl_ar = 'station_slave_array'
     #td_ar = 'trade_array'
     self.cache_data = {c.cd_pr: {}, c.cd_sm: {}, c.cd_st: {}, c.cd_stsl_ar: {}, c.td_ar: []}
     # TODO: перенести очистку лога в какое-нибудь другое место
     # очищаем лог файл и говорим о начале работы
     c.clear_file(c.log_file_name)
     c.logging('Begin create cache data')
     # получаем информацию о системах, станциях и ценах
     self.get_systems()
     self.get_stations()
     self.get_price()
     self.calc_best_routes()
     #self.process_trade()
     c.logging('End create cache data')