示例#1
0
    def __init__(self, sleep_seconds=5, time_step=None, schedule=None):
        """Initializes the time simulation"""
        self.sleep_seconds = sleep_seconds
        self.time_step = time_step
        if self.time_step is None:
            self.time_step = datetime.timedelta(minutes=self.sleep_seconds)

        # Read data from disk
        self.raw_df = pd.read_csv(
            f"{Path(__file__).parents[0]}/data/cta_stations.csv"
        ).sort_values("order")

        # Define the train schedule (same for all trains)
        self.schedule = schedule
        if schedule is None:
            self.schedule = {
                TimeSimulation.weekdays.mon: {0: TimeSimulation.ten_min_frequency},
                TimeSimulation.weekdays.tue: {0: TimeSimulation.ten_min_frequency},
                TimeSimulation.weekdays.wed: {0: TimeSimulation.ten_min_frequency},
                TimeSimulation.weekdays.thu: {0: TimeSimulation.ten_min_frequency},
                TimeSimulation.weekdays.fri: {0: TimeSimulation.ten_min_frequency},
                TimeSimulation.weekdays.sat: {0: TimeSimulation.ten_min_frequency},
                TimeSimulation.weekdays.sun: {0: TimeSimulation.ten_min_frequency},
            }

        self.train_lines = [
            Line(Line.colors.blue, self.raw_df[self.raw_df["blue"]]),
            Line(Line.colors.red, self.raw_df[self.raw_df["red"]]),
            Line(Line.colors.green, self.raw_df[self.raw_df["green"]]),
        ]
示例#2
0
    def __init__(self):
        '''
        Creates the Lines object
        '''

        self.red_line = Line('red')
        self.green_line = Line('green')
        self.blue_line = Line('blue')
示例#3
0
    def str2line(str_line):
        """str to Line object"""

        obj_line = Line()

        obj_line.freq = float(str_line[0:13])
        obj_line.freq_err = float(str_line[13:21])

        obj_line.log_I = float(str_line[21:29])
        obj_line.int_deg_freedom = int(str_line[29:31])

        obj_line.E = float(str_line[31:41])
        obj_line.g = int(CatConverter.__decode_quant(str_line[41:44]))

        obj_line.int_cat_tag = int(str_line[44:51])

        str_q = str_line[55:79]
        int_fmt = int(str_line[51:55])
        dict_qu, dict_ql = CatConverter.__read_quanta(str_q, int_fmt)

        obj_line.q_upper = dict_qu
        obj_line.q_lower = dict_ql
        obj_line.int_fmt = int_fmt

        return obj_line
示例#4
0
    def __init__(self, sleep_seconds=5, time_step=None, schedule=None):
        '''
        Initializes the time simulation
        '''

        self.sleep_seconds = sleep_seconds
        self.time_step = time_step
        if self.time_step is None:
            self.time_step = datetime.timedelta(minutes=self.sleep_seconds)

        # Read data from disk
        data = utils.get_data_path('cta_stations.csv')
        self.raw_df = pd.read_csv(data).sort_values('order')

        # Define the train schedule (same for all trains)
        self.schedule = schedule
        if schedule is None:
            self.schedule = {
                TimeSimulation.weekdays.mon: {
                    0: TimeSimulation.ten_min_frequency
                },
                TimeSimulation.weekdays.tue: {
                    0: TimeSimulation.ten_min_frequency
                },
                TimeSimulation.weekdays.wed: {
                    0: TimeSimulation.ten_min_frequency
                },
                TimeSimulation.weekdays.thu: {
                    0: TimeSimulation.ten_min_frequency
                },
                TimeSimulation.weekdays.fri: {
                    0: TimeSimulation.ten_min_frequency
                },
                TimeSimulation.weekdays.sat: {
                    0: TimeSimulation.ten_min_frequency
                },
                TimeSimulation.weekdays.sun: {
                    0: TimeSimulation.ten_min_frequency
                },
            }

        self.train_lines = [
            Line(Line.colors.blue, self.raw_df[self.raw_df['blue']]),
            Line(Line.colors.red, self.raw_df[self.raw_df['red']]),
            Line(Line.colors.green, self.raw_df[self.raw_df['green']]),
        ]
示例#5
0
    def test_cannot_create_invalid_line(self):

        """
        Test cannot create an invalid line
        with an empty cell list and invalid player
        """

        with self.assertRaises(ValueError):
            self.line_no_cells = Line([], 3)
示例#6
0
    def setUp(self):

        self.cell1 = Cell(1, 1, 0)
        self.cell2 = Cell(1, 1, 1)

        self.line = Line([
            self.cell1,
            self.cell2
        ], 1)
示例#7
0
    def test_can_return_matching_lines_for_cell(self):

        """
        Test can return a matching line for a cell
        """

        line = Line([
            self.cell1,
        ], 1)

        line2 = Line([
            self.cell3
        ], 1)

        self.game.lines = [line, line2]

        cell = Cell(1, 2, 1)

        matches = self.game.get_matching_lines_for_cell(cell)

        self.assertEqual(len(matches), 2)
示例#8
0
    def str2line(str_line, int_fmt):
        """str to Line object"""

        obj_line = Line()
        obj_line.freq = float(str_line[36:51])
        obj_line.freq_err = float(str_line[51:60])

        obj_line.str_lin_text = str_line[60:-1]

        str_q = str_line[0:36]
        dict_qu, dict_ql = LinConverter.__read_quanta(str_q, int_fmt)

        obj_line.int_fmt = int_fmt
        obj_line.q_upper = dict_qu
        obj_line.q_lower = dict_ql

        return obj_line
示例#9
0
    def test_can_create_a_new_line_for_cells_matching(self):

        line = Line([
            self.cell1,
        ], 1)

        self.game.lines.append(line)

        lines_count = len(self.game.lines)

        self.game.col_counters = {
            3: 1
        }

        self.game.add_move_to_the_board(3)

        self.assertEqual(lines_count + 2, len(self.game.lines))
示例#10
0
    def dowlnoad_index(self, download_index):
        log = logging.getLogger('DOWNLOAD')

        def cb(x, y):
            GLib.idle_add(self.parent.bar1, y / x)

        to_download = self.remote_index.exclude('/Cache.Windows/')
        GLib.idle_add(self.parent.bar2,
                      1 - download_index.size / to_download.size)

        for file in sorted(download_index, key=lambda x: x.size):
            local = Line(str(file))
            local.prefix = self.local_index.prefix

            if self.kill_event.is_set():
                return

            GLib.idle_add(self.parent.status_label, 'Download: ' + file.path)

            file_dir = os.path.dirname(local.full_path)
            if not os.path.exists(file_dir):
                os.makedirs(file_dir)

            try:
                data = file.download(self.kill_event, cb)
            except Exception as e:
                log.error(f'Download error: {e}')
                continue
            if data:
                with open(local.full_path, 'wb+') as f:
                    f.write(data)

            if file not in self.local_index:
                self.local_index.add(file)
                self.local_index.to_file(index_local)

            download_index.remove(file)
            GLib.idle_add(self.parent.bar2,
                          1 - download_index.size / to_download.size)

        log.info('Download ended')
示例#11
0
    def create(line_id, site_id, line_name):
        line = Line(line_id=line_id, site_id=site_id, line_name=line_name)

        return line.save()
示例#12
0
 def __init__(self):
     """Creates the Lines object"""
     self.red_line = Line("red")
     self.green_line = Line("green")
     self.blue_line = Line("blue")
示例#13
0
from models import Point, Line, LineType
import settings

starting_lines = [
    Line(
        point_a=Point(x=-5, y=settings.STARTING_AREA_Y),
        point_b=Point(x=settings.STARTING_AREA_X, y=settings.STARTING_AREA_Y),
        type=LineType.ACCELERATION,
    )
]
 def __init__(self):
     self.red_line = Line("red")
     self.green_line = Line("green")
     self.blue_line = Line("blue")
示例#15
0
文件: lines.py 项目: sheu/udacity
 def __init__(self, name="Default"):
     """Creates the Lines object"""
     self.red_line = Line("red")
     self.green_line = Line("green")
     self.blue_line = Line("blue")
     self.name = name
示例#16
0
 def __init__(self):
     """Creates the Lines object"""
     self._lines = [Line('red'), Line('green'), Line('blue')]
示例#17
0
from models import Track, Line, Point
from dateutil import parser

example_track = Track(
    start_date=parser.parse("2010-01-01"), end_date=parser.parse("2020-01-01")
)
example_track.lines.append(Line(point_a=Point(x=-10, y=20), point_b=Point(x=50, y=25)))
 def __init__(self):
     """Creates the Lines object"""
     logger.info(f'in lines init')
     self.red_line = Line("red")
     self.green_line = Line("green")
     self.blue_line = Line("blue")
示例#19
0
Shapes = ClassDiagram.find('Shapes')
Connectors = ClassDiagram.find('Connectors')

## Get info about the diagram itself
DiagramWidth = int(ClassDiagram.get('Width'))
DiagramHeight = int(ClassDiagram.get('Height'))

# Use the classes defined in the file models.py and extract information
# from the xml nodes to create instances of those classes, then store them
for shape in Shapes.findall('Class'):
    c = Card(shape.get('Name'),(shape.get('X'),shape.get('Y')), \
            shape.get('Width'), shape.get('Height'))
    Cards.append(c)

for connector in Connectors:
    l = Line(connector.tag, (connector.get('X'), connector.get('Y')),
             connector.get('Width'))
    Lines.append(l)

#Just to check

#for card in Cards:
#    print 'Card name is %s'%(card.GetName())
#    coordinates = [card.GetX(),card.GetY()]
#    print 'Card coordinates are (%s,%s)'%(coordinates[0],coordinates[1])
#    print 'Card width is %s'%(card.GetWidth())
#    print ''

#for line in Lines:
#    print 'Line Type is %s'%(line.GetType())
#    coordinates = [line.GetX(),line.GetY()]
#    print 'Line coordinates are (%s,%s)'%(coordinates[0],coordinates[1])