Exemplo n.º 1
0
class JobTests(AbstractEntityApiTestCase):

    def setUp(self):
        self.station = Station(name='MyTestStation')
        self.station.save()
        self.box = Box(station=self.station, address='My address str. 4')
        self.box.save()
        self.stand = Stand(box=self.box, name='MyStand')
        self.stand.save()
        self.service = Service(name='TestService',
                               min_duration=datetime.timedelta(minutes=30),
                               max_duration=datetime.timedelta(minutes=30),
                               min_cost=500,
                               max_cost=1000)
        self.service.save()

    def tearDown(self):
        self.station.delete()
        self.box.delete()
        self.stand.delete()
        self.service.delete()

    def _create_job(self, client, services, date_time):
        data = {
            'client': client,
            'selected_services': services,
            'date': date_time
        }
        return self._call_rest('post', 'job/', data)

    def test_job_creation(self):
        selected_services = [1, 2]
        date = '2016-01-11T03:00:07.451Z'
        client = {
            'phone': '8 999 000 0000',
            'car': {'model': 'Impreza', 'manufacturer': 'Subaru'}
        }

        job = self._create_job(client, selected_services, date)
        self.assertEqual(job.get('client'), 1)
        self.assertEqual(job.get('stand'), 1)
        self.assertEqual(job.get('date_time'), '2016-01-11T03:00:07.451000Z')

    def test_job_not_assigned_to_one_time(self):
        selected_services = [1]
        date1 = '2016-01-11T03:00:07.451Z'
        client = {
            'phone': '8-100-000-0000',
            'car': {'model': 'Impreza', 'manufacturer': 'Subaru'}
        }
        date2 = '2016-01-11T03:00:00.000Z'
        date3 = '2016-01-11T02:59:00.000Z'

        job = self._create_job(client, selected_services, date1)
        self.assertEqual(job['stand'], self.stand.id)
        job = self._create_job(client, selected_services, date2)
        self.assertEqual(job['detail'], 'No free stands for accept job')
        job = self._create_job(client, selected_services, date3)
        log.warn(job)
Exemplo n.º 2
0
    def import_all(cls):
        cls.objects.all().delete()

        prm = create_prm(cls.RDF_TYPE)
        res = request_metro(prm)
        data = parse_response(res)

        for d in data:
            try:
                date = dp.parse(d['dc:date'])

                rw = cls(ld_context=d['@context'],
                         ld_id=d['@id'],
                         ld_type=d['@type'],
                         same_as=d['owl:sameAs'],
                         date=date,
                         title=d['dc:title'],
                         operator=d['odpt:operator'],
                         line_code=d['odpt:lineCode'],
                         region=d['ug:region'])
                rw.save()

                # save StationOrder
                so_list = d['odpt:stationOrder']
                for so in so_list:
                    st = Station.get_or_create(so['odpt:station'])
                    StationOrder.get_or_create(rw, st, so['odpt:index'])
                # save TravelTime
                tt_list = d['odpt:travelTime']
                for tt in tt_list:
                    fs = Station.get_or_create(tt['odpt:fromStation'])
                    ts = Station.get_or_create(tt['odpt:toStation'])
                    TravelTime.get_or_create(rw, fs, ts,
                                             tt['odpt:necessaryTime'],
                                             tt['odpt:trainType'])
                # save WomenOnlyCar
                if 'odpt:womenOnlyCar' in d:
                    woc_list = d['odpt:womenOnlyCar']
                    for woc in woc_list:
                        fs = Station.get_or_create(woc['odpt:fromStation'])
                        ts = Station.get_or_create(woc['odpt:toStation'])
                        time_from = dp.parse(
                            woc['odpt:availableTimeFrom']).time()
                        time_until = dp.parse(
                            woc['odpt:availableTimeUntil']).time()
                        WomenOnlyCar.get_or_create(rw, fs, ts,
                                                   woc['odpt:operationDay'],
                                                   time_from, time_until,
                                                   woc['odpt:carComposition'],
                                                   woc['odpt:carNumber'])
            except:
                print d
                raise
Exemplo n.º 3
0
 def setUp(self):
     self.station = Station(name='MyTestStation')
     self.station.save()
     self.box = Box(station=self.station, address='My address str. 4')
     self.box.save()
     self.stand = Stand(box=self.box, name='MyStand')
     self.stand.save()
     self.service = Service(name='TestService',
                            min_duration=datetime.timedelta(minutes=30),
                            max_duration=datetime.timedelta(minutes=30),
                            min_cost=500,
                            max_cost=1000)
     self.service.save()
Exemplo n.º 4
0
def new_station(request):
    if request.method == 'POST':
        # save new post
        name = request.POST['name_station']
        num_station = request.POST['num_station']
        date_creation = datetime.now()

        station = Station(name=name, num_station=num_station, date_creation=date_creation)
        station.save()

        stations = Station.objects
        return HttpResponseRedirect('/')
    else:
        return render(request, 'new_station.html')
Exemplo n.º 5
0
def new_station(request):
    if request.method == 'POST':
        # save new post
        name = request.POST['name_station']
        num_station = request.POST['num_station']
        date_creation = datetime.now()

        station = Station(name=name,
                          num_station=num_station,
                          date_creation=date_creation)
        station.save()

        stations = Station.objects
        return HttpResponseRedirect('/')
    else:
        return render(request, 'new_station.html')
Exemplo n.º 6
0
    def import_all(cls):
        cls.objects.all().delete()

        prm = create_prm(cls.RDF_TYPE)
        res = request_metro(prm)
        data  = parse_response(res)
        
        for d in data:
            try:
                date = dp.parse(d['dc:date'])

                rw = cls(ld_context   = d['@context'],
                    ld_id        = d['@id'],
                    ld_type      = d['@type'],
                    same_as      = d['owl:sameAs'],
                    date         = date,
                    title        = d['dc:title'],
                    operator     = d['odpt:operator'],
                    line_code = d['odpt:lineCode'],
                    region       = d['ug:region']
                    )
                rw.save()

                # save StationOrder
                so_list = d['odpt:stationOrder']
                for so in so_list:
                    st = Station.get_or_create(so['odpt:station'])
                    StationOrder.get_or_create(rw, st, so['odpt:index'])
                # save TravelTime 
                tt_list = d['odpt:travelTime']
                for tt in tt_list:
                    fs = Station.get_or_create(tt['odpt:fromStation'])
                    ts = Station.get_or_create(tt['odpt:toStation'])
                    TravelTime.get_or_create(rw, fs, ts, tt['odpt:necessaryTime'], tt['odpt:trainType'])
                # save WomenOnlyCar 
                if 'odpt:womenOnlyCar' in d:
                    woc_list = d['odpt:womenOnlyCar']
                    for woc in woc_list:
                        fs = Station.get_or_create(woc['odpt:fromStation'])
                        ts = Station.get_or_create(woc['odpt:toStation'])
                        time_from = dp.parse(woc['odpt:availableTimeFrom']).time()
                        time_until = dp.parse(woc['odpt:availableTimeUntil']).time()
                        WomenOnlyCar.get_or_create(rw, fs, ts, woc['odpt:operationDay'], time_from, time_until,
                                woc['odpt:carComposition'], woc['odpt:carNumber'])
            except:
                print d
                raise
Exemplo n.º 7
0
def get_station_list(request):

    if request.method == "POST":
        return Http404

    js = {}
    js['stations'] = [st.to_json() for st in Station.get_metro_stations()]
    return HttpResponse(json.dumps(js), content_type='application/json')
Exemplo n.º 8
0
def get_station_list(request):

    if request.method == "POST":
        return Http404

    js = {}
    js['stations'] = [st.to_json() for st in Station.get_metro_stations()]
    return HttpResponse(json.dumps(js), content_type='application/json')
Exemplo n.º 9
0
    def import_all(cls):
        prm = create_prm(cls.RDF_TYPE)
        res = request_metro(prm)
        data  = parse_response(res)
        
        instances = []
        for d in data:
            try:
                date = dp.parse(d['dc:date'])
                valid = dp.parse(d['dct:valid'])
                from_station = Station.get_or_create(d['odpt:fromStation'])
                starting_station = Station.get_or_create(d['odpt:startingStation'])
                terminal_station = Station.get_or_create(d['odpt:terminalStation'])
                to_station = Station.get_or_create(d['odpt:toStation'])

                cls(ld_context       = d['@context'],
                    ld_id            = d['@id'],
                    ld_type          = d['@type'],
                    date             = date,
                    valid            = valid,
                    delay            = d['odpt:delay'],
                    frequency        = d['odpt:frequency'],
                    from_station     = from_station,
                    rail_direction   = d['odpt:railDirection'],
                    railway          = d['odpt:railway'],
                    starting_station = starting_station,
                    terminal_station = terminal_station,
                    to_station       = to_station,
                    train_number     = d['odpt:trainNumber'],
                    train_owner      = d['odpt:trainOwner'],
                    train_type       = d['odpt:trainType'],
                    same_as          = d['owl:sameAs'],
                    from_station_raw  = d['odpt:fromStation'],
                    starting_station_raw  = d['odpt:startingStation'],
                    terminal_station_raw  = d['odpt:terminalStation'],
                    to_station_raw  = d['odpt:toStation'],
                    ).save()
            except:
                print sys.exc_info() 
                print d
Exemplo n.º 10
0
 def setUp(self):
     self.station = Station(name='MyTestStation')
     self.station.save()
     self.box = Box(station=self.station, address='My address str. 4')
     self.box.save()
     self.stand = Stand(box=self.box, name='MyStand')
     self.stand.save()
     self.service = Service(name='TestService',
                            min_duration=datetime.timedelta(minutes=30),
                            max_duration=datetime.timedelta(minutes=30),
                            min_cost=500,
                            max_cost=1000)
     self.service.save()
Exemplo n.º 11
0
def add_station_view(request):
    params = json.loads(request.body)
    company_id = params.get('company')
    company = Company.objects.get(id=company_id)
    station = Station()
    station.name = params.get('name')
    station.capacity = params.get('capacity')
    station.mode = params.get('mode')
    station.is_self_consume = params.get('is_self_consume')
    station.is_self_consume_discount = params.get('is_self_consume_discount')
    station.company = company
    station.save()

    return json_response(station.to_dict())
Exemplo n.º 12
0

from station.models import Station
from station.models import Location
from station.models import Observation

with open('../data/station/mesowest_csv.tbl.20130903T1304', 'r') as csvfile:
    reader = csv.reader(csvfile)
    for line in reader:
        break
        if line[0] == 'primary id':
            pass
        mesonet_id = line[0]
        station_name = line[2]
        print "Saved STATION: %s with name: %s" % (mesonet_id, station_name)        
        station = Station(mesonet_id= mesonet_id, name= station_name)
        station.save()


with open('../data/observation/mesowest.out.20130903T1304', 'r') as csvfile:
    reader = csv.reader(csvfile)
    for line in reader:
        if len(line) > 0 and len(line[0].split()) == 16 and str(line[0]).split()[0] != 'STN':
            station = str(line[0]).split()[0]
            s = str(line[0]).split()[1]
            year = int(s[:4])
            month = int(s[4:-7])
            day = int(s[6:-5])
            hour = int(s[9:-2])
            minute = int(s[11:])
            mnet = str(line[0]).split()[2]
Exemplo n.º 13
0
class JobTests(AbstractEntityApiTestCase):
    def setUp(self):
        self.station = Station(name='MyTestStation')
        self.station.save()
        self.box = Box(station=self.station, address='My address str. 4')
        self.box.save()
        self.stand = Stand(box=self.box, name='MyStand')
        self.stand.save()
        self.service = Service(name='TestService',
                               min_duration=datetime.timedelta(minutes=30),
                               max_duration=datetime.timedelta(minutes=30),
                               min_cost=500,
                               max_cost=1000)
        self.service.save()

    def tearDown(self):
        self.station.delete()
        self.box.delete()
        self.stand.delete()
        self.service.delete()

    def _create_job(self, client, services, date_time):
        data = {
            'client': client,
            'selected_services': services,
            'date': date_time
        }
        return self._call_rest('post', 'job/', data)

    def test_job_creation(self):
        selected_services = [1, 2]
        date = '2016-01-11T03:00:07.451Z'
        client = {
            'phone': '8 999 000 0000',
            'car': {
                'model': 'Impreza',
                'manufacturer': 'Subaru'
            }
        }

        job = self._create_job(client, selected_services, date)
        self.assertEqual(job.get('client'), 1)
        self.assertEqual(job.get('stand'), 1)
        self.assertEqual(job.get('date_time'), '2016-01-11T03:00:07.451000Z')

    def test_job_not_assigned_to_one_time(self):
        selected_services = [1]
        date1 = '2016-01-11T03:00:07.451Z'
        client = {
            'phone': '8-100-000-0000',
            'car': {
                'model': 'Impreza',
                'manufacturer': 'Subaru'
            }
        }
        date2 = '2016-01-11T03:00:00.000Z'
        date3 = '2016-01-11T02:59:00.000Z'

        job = self._create_job(client, selected_services, date1)
        self.assertEqual(job['stand'], self.stand.id)
        job = self._create_job(client, selected_services, date2)
        self.assertEqual(job['detail'], 'No free stands for accept job')
        job = self._create_job(client, selected_services, date3)
        log.warn(job)