def save_carriers(elements):
    from app.models.carrier import Carrier
    for json_element in elements:
        if json_element["mnc"] and json_element["mcc"] and json_element["name"]:
            Carrier.add_new_carrier(mcc=json_element["mcc"],
                                    mnc=json_element["mnc"],
                                    name=json_element["name"])
    def populate(self):
        # devices
        device1 = Device(device_id="1",
                         creation_date=datetime.now() + timedelta(days=-2))
        device2 = Device(device_id="2", creation_date=datetime.now())
        device3 = Device(device_id="3", creation_date=datetime.now())
        device4 = Device(device_id="4", creation_date=datetime.now())

        # sims
        sim1 = Sim(serial_number="123")
        sim2 = Sim(serial_number="456")
        sim3 = Sim(serial_number="789")

        sim1.devices.append(device1)
        sim1.devices.append(device2)
        sim2.devices.append(device3)
        sim3.devices.append(device4)

        # carriers
        carrier1 = Carrier(name="test_carrier_1")
        carrier2 = Carrier(name="test_carrier_2")

        carrier1.sims.append(sim1)
        carrier1.sims.append(sim2)
        carrier2.sims.append(sim3)

        db.session.add(carrier1)
        db.session.add(carrier2)
        db.session.commit()
Exemplo n.º 3
0
def set_events_context(jsonvar):
    from app.models.device import Device
    device = Device.get_device_or_add_it(jsonvar["device_records"])
    app_version_code = jsonvar["device_records"]["app_version_code"]

    from app.models.sim import Sim
    sim = Sim.get_sim_or_add_it(jsonvar["sim_records"])

    if sim:
        # Get carrier or add it, if it does not exist
        from app.models.carrier import Carrier
        carrier = Carrier.get_carrier_or_add_it(
            mnc=jsonvar["sim_records"]["mnc"],
            mcc=jsonvar["sim_records"]["mcc"])

        # Link carrier with sim
        carrier.add_sim(sim)

        # Link sim with device
        sim.add_device(device)

        db.session.add(sim)
        db.session.add(carrier)

    # add new device, sim or carrier
    try:
        db.session.commit()
    except Exception as e:
        db.session.rollback()
        application.logger.error("Error adding device or sim to database " +
                                 str(e))

    return device, sim, app_version_code
Exemplo n.º 4
0
def set_events_context(jsonvar):
    from app.models.device import Device
    device = Device.get_device_or_add_it(jsonvar["device_records"])
    app_version_code = jsonvar["device_records"]["app_version_code"]

    from app.models.sim import Sim
    sim = Sim.get_sim_or_add_it(jsonvar["sim_records"])

    if sim:
        # Get carrier or add it, if it does not exist
        from app.models.carrier import Carrier
        carrier = Carrier.get_carrier_or_add_it(mnc=jsonvar["sim_records"]["mnc"], mcc=jsonvar["sim_records"]["mcc"])

        # Link carrier with sim
        carrier.add_sim(sim)

        # Link sim with device
        sim.add_device(device)

        db.session.add(sim)
        db.session.add(carrier)

    # add new device, sim or carrier
    db.session.commit()

    return device, sim, app_version_code
    def populate(self):
        # devices
        device1 = Device(device_id="1")
        device2 = Device(device_id="2")
        device3 = Device(device_id="3")
        device4 = Device(device_id="4")

        # sims
        sim1 = Sim(serial_number="123")
        sim2 = Sim(serial_number="456")
        sim3 = Sim(serial_number="789")

        sim1.devices.append(device1)
        sim1.devices.append(device2)
        sim2.devices.append(device1)
        sim2.devices.append(device3)
        sim3.devices.append(device4)

        # carriers
        carrier1 = Carrier(name="test_carrier_1")
        carrier2 = Carrier(name="test_carrier_2")

        carrier1.sims.append(sim1)
        carrier1.sims.append(sim2)
        carrier2.sims.append(sim3)

        # GSM events
        event1 = GsmEvent(date=datetime.now() + timedelta(days=-2))
        event2 = GsmEvent(date=datetime.now())
        event3 = GsmEvent(date=datetime.now())
        event4 = GsmEvent(date=datetime.now())
        event5 = GsmEvent(date=datetime.now())

        sim1.events.append(event1)
        sim1.events.append(event2)
        sim3.events.append(event3)
        sim3.events.append(event4)
        sim3.events.append(event5)

        device1.events = [event1, event2]
        device2.events = [event3]
        device3.events = [event4, event5]

        db.session.add(carrier1)
        db.session.add(carrier2)
        db.session.commit()
Exemplo n.º 6
0
    def populate(self):
        # sims
        sim1 = Sim(serial_number="123",
                   creation_date=datetime.now() + timedelta(days=-2))
        sim2 = Sim(serial_number="456", creation_date=datetime.now())
        sim3 = Sim(serial_number="789", creation_date=datetime.now())

        # carriers
        carrier1 = Carrier(name="test_carrier_1")
        carrier2 = Carrier(name="test_carrier_2")

        carrier1.sims.append(sim1)
        carrier1.sims.append(sim2)
        carrier2.sims.append(sim3)

        db.session.add(carrier1)
        db.session.add(carrier2)
        db.session.commit()
Exemplo n.º 7
0
def link_observation_with_carrier(event):
    if event.mnc and event.mcc:
        from app.models.carrier import Carrier
        carrier = Carrier.get_carrier_or_add_it(mnc=event.mnc, mcc=event.mcc)
        event.carrier_id = carrier.id
Exemplo n.º 8
0
def link_observation_with_carrier(event):
    if event.mnc and event.mcc:
        from app.models.carrier import Carrier
        carrier = Carrier.get_carrier_or_add_it(mnc=event.mnc, mcc=event.mcc)
        event.carrier_id = carrier.id