Beispiel #1
0
def loop(light, tap, bri_phase_map):
    from itertools import izip
    from phase import phase, sinus, charge, constant
    from sunphase import get_ct_phase, rise_and_set, MIREK
    last_bri = last_ct = 0
    sun = rise_and_set(52.053055, 5.638889, -6.0)
    t_wake = time(7,15)
    t_sleep = time(22,15)
    while True:
        t_rise, t_set = sun.next()
        t_now = datetime.now().time()
        ct_phase = get_ct_phase(t_wake, t_sleep, t_rise, t_set, t_now)
        if t_wake <= t_now < t_sleep:
            bri_phase = phase(t_wake, t_sleep, bri_phase_map, 0, 255)
        else:
            bri_phase = phase(t_sleep, t_wake, constant(0), 0, 0)
        for color_temp, brightness in izip(ct_phase, bri_phase):
            s = tap.next()
            print ".",
            if color_temp != last_ct or brightness != last_bri:
                last_bri = brightness
                last_ct = color_temp
                #if s == 17: # button 2 is auto
                light.send(dict(ct=color_temp, bri=brightness, on=True))
                print "\n%s; %dK; %.1f%% tap=%d" % (datetime.now().strftime("%a %H:%M:%S"), MIREK/color_temp, brightness/2.55, s),
            stdout.flush()
            sleep(2.0)
        sleep(1.0)
Beispiel #2
0
 def phase_calc(event):
     if not event.inaxes == emgui.event_phase.ax:
         raise Exception('Improper axis')
     print(emgui.circle_1.artist.radius)
     print(emgui.circle_1.artist.center)
     phase.phase(emgui.circle_1.artist.center, emgui.circle_1.artist.radius,
                 emgui.circle_2.artist.center, emgui.circle_2.artist.radius,
                 emdata)
     emgui.phase_holo()
Beispiel #3
0
def brightness_cycle(t_wake, t_sleep, f):
    t = yield
    while True:
        p = phase(t_wake(), t_sleep(), f, 0, 255)
        try:
            while True:
                t = yield p.send(t)
        except StopIteration:
            t = yield 0
Beispiel #4
0
    def realinit(self):

        self.docklist = [
            'self.drho', 'self.dlamb', 'self.dalpha', 'self.dbeta',
            'self.dphase', 'self.dcontrols'
        ]
        self.area = DockArea()

        self.drho = Dock("Particle Density \u2374", closable=True)
        self.dlamb = Dock("Hopping Rate \u03bb", closable=True)
        self.dphase = Dock("Phase Diagram", closable=True)
        self.dcontrols = Dock("Controls", closable=True)
        self.dalpha = Dock(
            "Current J and average density \u27e8\u2374\u27e9 as a function of \u03b1",
            closable=True)
        self.dbeta = Dock(
            "Current J and average density \u27e8\u2374\u27e9 as a function of \u03b2",
            closable=True)

        self.layout = QtGui.QHBoxLayout()
        self.layout.addWidget(self.area)
        self.mainframe.setLayout(self.layout)
        self.mainframe.setFrameStyle(QtGui.QFrame.Box | QtGui.QFrame.Raised)
        self.mainframe.setLineWidth(8)

        pg.setConfigOptions(antialias=True)

        self.lamb_po = lamb_pol.lamb_pol(self.dlamb)
        self.rh = rho.rho(self.drho)
        self.phas = phase.phase(self.dphase)
        self.jalph = jalpha.jalpha(self.dalpha, self.rh)
        self.jbet = jbeta.jbeta(self.dbeta, self.rh)
        self.slid = slider.Widget(self.dcontrols, self.lamb_po, self.phas,
                                  self.rh, self.jbet, self.jalph)
        self.lamb_po.receive(self.slid)

        # default values to restore is input
        self.savedlambdas = glo_var.lambdas[:]
        self.savedalpha = glo_var.alpha
        self.savedbeta = glo_var.beta
        self.savedl = glo_var.l

        self.pltlist = [['Lambda_fig', self.lamb_po.p1],
                        ['Density_fig', self.rh.p2],
                        ['Current_alpha_fig', self.jalph.p3],
                        ['Current_beta_fig', self.jbet.p4],
                        ['Phase_fig', self.phas.p5]]

        self.grid_view_1()
        self.setCentralWidget(self.area)
Beispiel #5
0
    def realinit(self):

        pg.setConfigOptions(antialias=True)

        self.lamb_po = lamb_pol.lamb_pol(self.layout)

        self.rh = rho.rho(self.layout)

        self.phas = phase.phase(self.layout)
        self.jalph = jalpha.jalpha(self.layout, self.rh)
        self.jbet = jbeta.jbeta(self.layout, self.rh)

        self.slid = slider.Widget(self.layout, self.lamb_po, self.phas,
                                  self.rh, self.jbet, self.jalph)
        self.lamb_po.receive(self.slid)
Beispiel #6
0
    def realinit(self):

        self.docklist = [
            'self.drho', 'self.dlamb', 'self.dalpha', 'self.dbeta',
            'self.dphase', 'self.dcontrols'
        ]
        self.area = DockArea()

        self.drho = Dock("\u03c1", closable=True)
        self.dlamb = Dock("\u03bb", closable=True)
        self.dphase = Dock("Phase", closable=True)
        self.dcontrols = Dock("Controls", closable=True)
        self.dalpha = Dock("\u03b1", closable=True)
        self.dbeta = Dock("\u03b2", closable=True)

        self.layout = QtGui.QHBoxLayout()
        self.layout.addWidget(self.area)
        self.mainframe.setLayout(self.layout)
        self.mainframe.setFrameStyle(QtGui.QFrame.Box | QtGui.QFrame.Raised)
        self.mainframe.setLineWidth(8)

        pg.setConfigOptions(antialias=True)

        self.lamb_po = lamb_pol.lamb_pol(self.dlamb)
        self.rh = rho.rho(self.drho)
        self.phas = phase.phase(self.dphase)
        self.jalph = jalpha.jalpha(self.dalpha, self.rh)
        self.jbet = jbeta.jbeta(self.dbeta, self.rh)
        self.slid = slider.Widget(self.dcontrols, self.lamb_po, self.phas,
                                  self.rh, self.jbet, self.jalph)
        self.lamb_po.receive(self.slid)

        self.pltlist = [['Lambdas_fig', self.lamb_po.p1],
                        ['Rho_fig', self.rh.p2], ['Jalpha_fig', self.jalph.p3],
                        ['Jbeta_fig', self.jbet.p4],
                        ['Phase_fig', self.phas.p5]]

        self.default_view_1()
        self.setCentralWidget(self.area)
Beispiel #7
0
def get_ct_phase(t_wake, t_sleep, t_rise, t_set, t):
    if isinstance(t, datetime): t = t.time()
    t_dawn_end = min(t_wake, t_rise)
    t_dusk_begin = max(t_sleep, t_set)
    t_dawn_begin = t_dawn_end.replace(hour=t_dawn_end.hour - 1)
    t_dusk_end = t_dusk_begin.replace(hour=t_dusk_begin.hour + 1) #TODO use datetime for proper rollover
    if t_rise <= t < t_set:
        return phase(t_rise, t_set, sinus(charge(2.)), CCT_SUN_RISE, CCT_AVG_SUMMER_SUNLIGHT)
    if t_wake <= t < t_rise:
        return phase(t_wake, t_rise, linear(), CCT_SUN_RISE, CCT_SUN_RISE)
    if t_set <= t < t_sleep:
        return phase(t_set, t_sleep, linear(), CCT_SUN_SET, CCT_SUN_SET)
    if t_dawn_begin <= t < t_dawn_end:
        return phase(t_dawn_begin, t_dawn_end, linear(), CCT_RED_SUN, CCT_SUN_RISE)
    if t_dusk_begin <= t < t_dusk_end:
        return phase(t_dusk_begin, t_dusk_end, linear(), CCT_SUN_SET, CCT_RED_SUN)
    if t_dusk_end <= t < time.max or time.min <= t < t_dawn_begin:
        return phase(t_dusk_end, t_dawn_begin, sinus(), CCT_RED_SUN, CCT_DEEP_NIGHT)
    raise Exception("Cannot match cycle: %s" % t)
Beispiel #8
0
    def setupUi(self, Dialog, game, ui):
        Dialog.setObjectName("Dialog")
        Dialog.resize(1200, 900)
        self.layoutWidget = QtWidgets.QWidget(Dialog)
        self.layoutWidget.setGeometry(QtCore.QRect(261, 21, 702, 781))
        self.layoutWidget.setObjectName("layoutWidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.layoutWidget)
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout.setObjectName("verticalLayout")
        self.Spielfeld_OF = QtWidgets.QFrame(self.layoutWidget)
        self.Spielfeld_OF.setMinimumSize(QtCore.QSize(700, 600))
        self.Spielfeld_OF.setMaximumSize(QtCore.QSize(800, 800))
        self.Spielfeld_OF.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.Spielfeld_OF.setFrameShadow(QtWidgets.QFrame.Raised)
        self.Spielfeld_OF.setObjectName("Spielfeld_OF")
        self.line = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line.setGeometry(QtCore.QRect(160, 360, 80, 3))
        self.line.setFrameShape(QtWidgets.QFrame.HLine)
        self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line.setObjectName("line")
        self.line_2 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_2.setGeometry(QtCore.QRect(460, 360, 80, 3))
        self.line_2.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_2.setObjectName("line_2")
        self.line_3 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_3.setGeometry(QtCore.QRect(360, 280, 80, 3))
        self.line_3.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_3.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_3.setObjectName("line_3")
        self.line_5 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_5.setGeometry(QtCore.QRect(260, 280, 80, 3))
        self.line_5.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_5.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_5.setObjectName("line_5")
        self.line_4 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_4.setGeometry(QtCore.QRect(250, 290, 3, 60))
        self.line_4.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_4.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_4.setObjectName("line_4")
        self.line_6 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_6.setGeometry(QtCore.QRect(450, 290, 3, 60))
        self.line_6.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_6.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_6.setObjectName("line_6")
        self.line_7 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_7.setGeometry(QtCore.QRect(250, 370, 3, 60))
        self.line_7.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_7.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_7.setObjectName("line_7")
        self.line_8 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_8.setGeometry(QtCore.QRect(450, 370, 3, 60))
        self.line_8.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_8.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_8.setObjectName("line_8")
        self.line_9 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_9.setGeometry(QtCore.QRect(260, 440, 80, 3))
        self.line_9.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_9.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_9.setObjectName("line_9")
        self.line_10 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_10.setGeometry(QtCore.QRect(360, 440, 80, 3))
        self.line_10.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_10.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_10.setObjectName("line_10")
        self.line_11 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_11.setGeometry(QtCore.QRect(350, 450, 3, 60))
        self.line_11.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_11.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_11.setObjectName("line_11")
        self.line_12 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_12.setGeometry(QtCore.QRect(350, 210, 3, 60))
        self.line_12.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_12.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_12.setObjectName("line_12")
        self.line_13 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_13.setGeometry(QtCore.QRect(350, 130, 3, 60))
        self.line_13.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_13.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_13.setObjectName("line_13")
        self.line_14 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_14.setGeometry(QtCore.QRect(350, 530, 3, 60))
        self.line_14.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_14.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_14.setObjectName("line_14")
        self.line_15 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_15.setGeometry(QtCore.QRect(360, 200, 180, 3))
        self.line_15.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_15.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_15.setObjectName("line_15")
        self.line_16 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_16.setGeometry(QtCore.QRect(160, 200, 180, 3))
        self.line_16.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_16.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_16.setObjectName("line_16")
        self.line_17 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_17.setGeometry(QtCore.QRect(360, 120, 280, 3))
        self.line_17.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_17.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_17.setObjectName("line_17")
        self.line_18 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_18.setGeometry(QtCore.QRect(60, 120, 280, 3))
        self.line_18.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_18.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_18.setObjectName("line_18")
        self.line_19 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_19.setGeometry(QtCore.QRect(560, 360, 80, 3))
        self.line_19.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_19.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_19.setObjectName("line_19")
        self.line_20 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_20.setGeometry(QtCore.QRect(60, 360, 80, 3))
        self.line_20.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_20.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_20.setObjectName("line_20")
        self.line_21 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_21.setGeometry(QtCore.QRect(160, 520, 180, 3))
        self.line_21.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_21.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_21.setObjectName("line_21")
        self.line_22 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_22.setGeometry(QtCore.QRect(360, 520, 180, 3))
        self.line_22.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_22.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_22.setObjectName("line_22")
        self.line_23 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_23.setGeometry(QtCore.QRect(360, 600, 280, 3))
        self.line_23.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_23.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_23.setObjectName("line_23")
        self.line_24 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_24.setGeometry(QtCore.QRect(60, 600, 280, 3))
        self.line_24.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_24.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_24.setObjectName("line_24")
        self.line_25 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_25.setGeometry(QtCore.QRect(650, 130, 3, 220))
        self.line_25.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_25.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_25.setObjectName("line_25")
        self.line_26 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_26.setGeometry(QtCore.QRect(650, 370, 3, 220))
        self.line_26.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_26.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_26.setObjectName("line_26")
        self.line_27 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_27.setGeometry(QtCore.QRect(150, 370, 3, 140))
        self.line_27.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_27.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_27.setObjectName("line_27")
        self.line_28 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_28.setGeometry(QtCore.QRect(550, 370, 3, 140))
        self.line_28.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_28.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_28.setObjectName("line_28")
        self.line_29 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_29.setGeometry(QtCore.QRect(550, 210, 3, 140))
        self.line_29.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_29.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_29.setObjectName("line_29")
        self.line_30 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_30.setGeometry(QtCore.QRect(150, 210, 3, 140))
        self.line_30.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_30.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_30.setObjectName("line_30")
        self.line_31 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_31.setGeometry(QtCore.QRect(50, 370, 3, 220))
        self.line_31.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_31.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_31.setObjectName("line_31")
        self.line_32 = QtWidgets.QFrame(self.Spielfeld_OF)
        self.line_32.setGeometry(QtCore.QRect(50, 130, 3, 220))
        self.line_32.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_32.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_32.setObjectName("line_32")
        self.label_312 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_312.setGeometry(QtCore.QRect(320, 250, 70, 70))
        self.label_312.setMaximumSize(QtCore.QSize(70, 70))
        self.label_312.setAcceptDrops(True)
        self.label_312.setAlignment(QtCore.Qt.AlignCenter)
        self.label_312.setObjectName("label_312")
        self.label_323 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_323.setGeometry(QtCore.QRect(420, 330, 70, 70))
        self.label_323.setMaximumSize(QtCore.QSize(70, 70))
        self.label_323.setAcceptDrops(True)
        self.label_323.setAlignment(QtCore.Qt.AlignCenter)
        self.label_323.setObjectName("label_323")
        self.label_231 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_231.setGeometry(QtCore.QRect(120, 480, 70, 70))
        self.label_231.setMaximumSize(QtCore.QSize(70, 70))
        self.label_231.setAcceptDrops(True)
        self.label_231.setAlignment(QtCore.Qt.AlignCenter)
        self.label_231.setObjectName("label_231")
        self.label_213 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_213.setGeometry(QtCore.QRect(510, 170, 70, 70))
        self.label_213.setMaximumSize(QtCore.QSize(70, 70))
        self.label_213.setAcceptDrops(True)
        self.label_213.setAlignment(QtCore.Qt.AlignCenter)
        self.label_213.setObjectName("label_213")
        self.label_233 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_233.setGeometry(QtCore.QRect(510, 480, 70, 70))
        self.label_233.setMaximumSize(QtCore.QSize(70, 70))
        self.label_233.setAcceptDrops(True)
        self.label_233.setAlignment(QtCore.Qt.AlignCenter)
        self.label_233.setObjectName("label_233")
        self.label_211 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_211.setGeometry(QtCore.QRect(120, 170, 70, 70))
        self.label_211.setMaximumSize(QtCore.QSize(70, 70))
        self.label_211.setAcceptDrops(True)
        self.label_211.setAlignment(QtCore.Qt.AlignCenter)
        self.label_211.setObjectName("label_211")
        self.label_131 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_131.setGeometry(QtCore.QRect(20, 560, 70, 70))
        self.label_131.setMaximumSize(QtCore.QSize(70, 70))
        self.label_131.setAcceptDrops(True)
        self.label_131.setAlignment(QtCore.Qt.AlignCenter)
        self.label_131.setObjectName("label_131")
        self.label_331 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_331.setGeometry(QtCore.QRect(220, 400, 70, 70))
        self.label_331.setMaximumSize(QtCore.QSize(70, 70))
        self.label_331.setAcceptDrops(True)
        self.label_331.setAlignment(QtCore.Qt.AlignCenter)
        self.label_331.setObjectName("label_331")
        self.label_311 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_311.setGeometry(QtCore.QRect(220, 250, 70, 70))
        self.label_311.setMaximumSize(QtCore.QSize(70, 70))
        self.label_311.setAcceptDrops(True)
        self.label_311.setAlignment(QtCore.Qt.AlignCenter)
        self.label_311.setObjectName("label_311")
        self.label_232 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_232.setGeometry(QtCore.QRect(320, 490, 70, 70))
        self.label_232.setMaximumSize(QtCore.QSize(70, 70))
        self.label_232.setAcceptDrops(True)
        self.label_232.setAlignment(QtCore.Qt.AlignCenter)
        self.label_232.setObjectName("label_232")
        self.label_221 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_221.setGeometry(QtCore.QRect(120, 320, 70, 70))
        self.label_221.setMaximumSize(QtCore.QSize(70, 70))
        self.label_221.setAcceptDrops(True)
        self.label_221.setAlignment(QtCore.Qt.AlignCenter)
        self.label_221.setObjectName("label_221")
        self.label_223 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_223.setGeometry(QtCore.QRect(510, 320, 70, 70))
        self.label_223.setMaximumSize(QtCore.QSize(70, 70))
        self.label_223.setAcceptDrops(True)
        self.label_223.setAlignment(QtCore.Qt.AlignCenter)
        self.label_223.setObjectName("label_223")
        self.label_112 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_112.setGeometry(QtCore.QRect(310, 80, 70, 70))
        self.label_112.setMaximumSize(QtCore.QSize(70, 70))
        self.label_112.setAcceptDrops(True)
        self.label_112.setAlignment(QtCore.Qt.AlignCenter)
        self.label_112.setObjectName("label_112")
        self.label_123 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_123.setGeometry(QtCore.QRect(620, 320, 70, 70))
        self.label_123.setMaximumSize(QtCore.QSize(70, 70))
        self.label_123.setAcceptDrops(True)
        self.label_123.setAlignment(QtCore.Qt.AlignCenter)
        self.label_123.setObjectName("label_123")
        self.label_133 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_133.setGeometry(QtCore.QRect(610, 560, 70, 70))
        self.label_133.setMaximumSize(QtCore.QSize(70, 70))
        self.label_133.setAcceptDrops(True)
        self.label_133.setAlignment(QtCore.Qt.AlignCenter)
        self.label_133.setObjectName("label_133")
        self.label_332 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_332.setGeometry(QtCore.QRect(320, 410, 70, 70))
        self.label_332.setMaximumSize(QtCore.QSize(70, 70))
        self.label_332.setAcceptDrops(True)
        self.label_332.setAlignment(QtCore.Qt.AlignCenter)
        self.label_332.setObjectName("label_332")
        self.label_321 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_321.setGeometry(QtCore.QRect(210, 330, 70, 70))
        self.label_321.setMaximumSize(QtCore.QSize(70, 70))
        self.label_321.setAcceptDrops(True)
        self.label_321.setAlignment(QtCore.Qt.AlignCenter)
        self.label_321.setObjectName("label_321")
        self.label_132 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_132.setGeometry(QtCore.QRect(320, 570, 70, 70))
        self.label_132.setMaximumSize(QtCore.QSize(70, 70))
        self.label_132.setAcceptDrops(True)
        self.label_132.setAlignment(QtCore.Qt.AlignCenter)
        self.label_132.setObjectName("label_132")
        self.label_313 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_313.setGeometry(QtCore.QRect(410, 250, 70, 70))
        self.label_313.setMaximumSize(QtCore.QSize(70, 70))
        self.label_313.setAcceptDrops(True)
        self.label_313.setAlignment(QtCore.Qt.AlignCenter)
        self.label_313.setObjectName("label_313")
        self.label_212 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_212.setGeometry(QtCore.QRect(320, 170, 70, 70))
        self.label_212.setMaximumSize(QtCore.QSize(70, 70))
        self.label_212.setAcceptDrops(True)
        self.label_212.setAlignment(QtCore.Qt.AlignCenter)
        self.label_212.setObjectName("label_212")
        self.label_333 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_333.setGeometry(QtCore.QRect(410, 400, 70, 70))
        self.label_333.setMaximumSize(QtCore.QSize(70, 70))
        self.label_333.setAcceptDrops(True)
        self.label_333.setAlignment(QtCore.Qt.AlignCenter)
        self.label_333.setObjectName("label_333")
        self.label_121 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_121.setGeometry(QtCore.QRect(20, 330, 70, 70))
        self.label_121.setMaximumSize(QtCore.QSize(70, 70))
        self.label_121.setAcceptDrops(True)
        self.label_121.setAlignment(QtCore.Qt.AlignCenter)
        self.label_121.setObjectName("label_121")
        self.label_111 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_111.setGeometry(QtCore.QRect(10, 80, 70, 70))
        self.label_111.setMaximumSize(QtCore.QSize(70, 70))
        self.label_111.setAcceptDrops(True)
        self.label_111.setAlignment(QtCore.Qt.AlignCenter)
        self.label_111.setObjectName("label_111")
        self.label_113 = playing_field_label(self.Spielfeld_OF, game, ui)
        self.label_113.setGeometry(QtCore.QRect(610, 90, 70, 70))
        self.label_113.setMaximumSize(QtCore.QSize(70, 70))
        self.label_113.setAcceptDrops(True)
        self.label_113.setAlignment(QtCore.Qt.AlignCenter)
        self.label_113.setObjectName("label_113")
        self.verticalLayout.addWidget(self.Spielfeld_OF)
        self.Reset_pushButton = QtWidgets.QPushButton(self.layoutWidget)
        self.Reset_pushButton.setObjectName("Reset_pushButton")
        self.verticalLayout.addWidget(self.Reset_pushButton)
        self.layoutWidget1 = QtWidgets.QWidget(Dialog)
        self.layoutWidget1.setGeometry(QtCore.QRect(960, 20, 128, 780))
        self.layoutWidget1.setObjectName("layoutWidget1")
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.layoutWidget1)
        self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        spacerItem = QtWidgets.QSpacerItem(28, 778,
                                           QtWidgets.QSizePolicy.Minimum,
                                           QtWidgets.QSizePolicy.Expanding)
        self.horizontalLayout_2.addItem(spacerItem)
        self.player2 = QtWidgets.QGroupBox(self.layoutWidget1)
        self.player2.setObjectName("player2")
        self.gelb_1 = token_label(self.player2)
        self.gelb_1.setGeometry(QtCore.QRect(10, 600, 70, 70))
        self.gelb_1.setStyleSheet("")
        self.gelb_1.setText("")
        self.gelb_1.setPixmap(QtGui.QPixmap("gelb.png"))
        self.gelb_1.setObjectName("gelb_1")
        self.gelb_2 = token_label(self.player2)
        self.gelb_2.setGeometry(QtCore.QRect(10, 520, 70, 70))
        self.gelb_2.setStyleSheet("")
        self.gelb_2.setText("")
        self.gelb_2.setPixmap(QtGui.QPixmap("gelb.png"))
        self.gelb_2.setObjectName("gelb_2")
        self.gelb_3 = token_label(self.player2)
        self.gelb_3.setGeometry(QtCore.QRect(10, 450, 70, 70))
        self.gelb_3.setStyleSheet("")
        self.gelb_3.setText("")
        self.gelb_3.setPixmap(QtGui.QPixmap("gelb.png"))
        self.gelb_3.setObjectName("gelb_3")
        self.gelb_4 = token_label(self.player2)
        self.gelb_4.setGeometry(QtCore.QRect(10, 380, 70, 70))
        self.gelb_4.setStyleSheet("")
        self.gelb_4.setText("")
        self.gelb_4.setPixmap(QtGui.QPixmap("gelb.png"))
        self.gelb_4.setObjectName("gelb_4")
        self.gelb_5 = token_label(self.player2)
        self.gelb_5.setGeometry(QtCore.QRect(10, 310, 70, 70))
        self.gelb_5.setStyleSheet("")
        self.gelb_5.setText("")
        self.gelb_5.setPixmap(QtGui.QPixmap("gelb.png"))
        self.gelb_5.setObjectName("gelb_5")
        self.gelb_6 = token_label(self.player2)
        self.gelb_6.setGeometry(QtCore.QRect(10, 240, 70, 70))
        self.gelb_6.setStyleSheet("")
        self.gelb_6.setText("")
        self.gelb_6.setPixmap(QtGui.QPixmap("gelb.png"))
        self.gelb_6.setObjectName("gelb_6")
        self.gelb_7 = token_label(self.player2)
        self.gelb_7.setGeometry(QtCore.QRect(10, 170, 70, 70))
        self.gelb_7.setStyleSheet("")
        self.gelb_7.setText("")
        self.gelb_7.setPixmap(QtGui.QPixmap("gelb.png"))
        self.gelb_7.setObjectName("gelb_7")
        self.gelb_8 = token_label(self.player2)
        self.gelb_8.setGeometry(QtCore.QRect(10, 100, 70, 70))
        self.gelb_8.setStyleSheet("")
        self.gelb_8.setText("")
        self.gelb_8.setPixmap(QtGui.QPixmap("gelb.png"))
        self.gelb_8.setObjectName("gelb_8")
        self.gelb_9 = token_label(self.player2)
        self.gelb_9.setGeometry(QtCore.QRect(10, 30, 70, 70))
        self.gelb_9.setStyleSheet("")
        self.gelb_9.setText("")
        self.gelb_9.setPixmap(QtGui.QPixmap("gelb.png"))
        self.gelb_9.setObjectName("gelb_9")
        self.Sp2_phase = phase(self.player2)
        self.Sp2_phase.setGeometry(QtCore.QRect(10, 730, 57, 15))
        self.Sp2_phase.setStyleSheet("color: rgb(0, 0, 0);")
        self.Sp2_phase.setObjectName("Sp2_phase")
        self.horizontalLayout_2.addWidget(self.player2)
        self.layoutWidget2 = QtWidgets.QWidget(Dialog)
        self.layoutWidget2.setGeometry(QtCore.QRect(140, 20, 113, 780))
        self.layoutWidget2.setObjectName("layoutWidget2")
        self.horizontalLayout = QtWidgets.QHBoxLayout(self.layoutWidget2)
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.player1 = QtWidgets.QGroupBox(self.layoutWidget2)
        self.player1.setStyleSheet("color: rgb(204, 0, 0);")
        self.player1.setObjectName("player1")
        self.blau_1 = token_label(self.player1)
        self.blau_1.setGeometry(QtCore.QRect(10, 640, 65, 65))
        self.blau_1.setMaximumSize(QtCore.QSize(100, 100))
        self.blau_1.setAcceptDrops(True)
        self.blau_1.setAutoFillBackground(True)
        self.blau_1.setStyleSheet("")
        self.blau_1.setText("")
        self.blau_1.setPixmap(QtGui.QPixmap("blau.png"))
        self.blau_1.setWordWrap(False)
        self.blau_1.setObjectName("blau_1")
        self.blau_2 = token_label(self.player1)
        self.blau_2.setGeometry(QtCore.QRect(10, 560, 65, 65))
        self.blau_2.setMaximumSize(QtCore.QSize(100, 100))
        self.blau_2.setAcceptDrops(True)
        self.blau_2.setAutoFillBackground(True)
        self.blau_2.setStyleSheet("")
        self.blau_2.setText("")
        self.blau_2.setPixmap(QtGui.QPixmap("blau.png"))
        self.blau_2.setWordWrap(False)
        self.blau_2.setObjectName("blau_2")
        self.blau_3 = token_label(self.player1)
        self.blau_3.setGeometry(QtCore.QRect(10, 480, 65, 65))
        self.blau_3.setMaximumSize(QtCore.QSize(100, 100))
        self.blau_3.setAcceptDrops(True)
        self.blau_3.setAutoFillBackground(True)
        self.blau_3.setStyleSheet("")
        self.blau_3.setText("")
        self.blau_3.setPixmap(QtGui.QPixmap("blau.png"))
        self.blau_3.setWordWrap(False)
        self.blau_3.setObjectName("blau_3")
        self.blau_4 = token_label(self.player1)
        self.blau_4.setGeometry(QtCore.QRect(10, 400, 65, 65))
        self.blau_4.setMaximumSize(QtCore.QSize(100, 100))
        self.blau_4.setAcceptDrops(True)
        self.blau_4.setAutoFillBackground(True)
        self.blau_4.setStyleSheet("")
        self.blau_4.setText("")
        self.blau_4.setPixmap(QtGui.QPixmap("blau.png"))
        self.blau_4.setWordWrap(False)
        self.blau_4.setObjectName("blau_4")
        self.blau_5 = token_label(self.player1)
        self.blau_5.setGeometry(QtCore.QRect(10, 320, 65, 65))
        self.blau_5.setMaximumSize(QtCore.QSize(100, 100))
        self.blau_5.setAcceptDrops(True)
        self.blau_5.setAutoFillBackground(True)
        self.blau_5.setStyleSheet("")
        self.blau_5.setText("")
        self.blau_5.setPixmap(QtGui.QPixmap("blau.png"))
        self.blau_5.setWordWrap(False)
        self.blau_5.setObjectName("blau_5")
        self.blau_6 = token_label(self.player1)
        self.blau_6.setGeometry(QtCore.QRect(10, 250, 65, 65))
        self.blau_6.setMaximumSize(QtCore.QSize(100, 100))
        self.blau_6.setAcceptDrops(True)
        self.blau_6.setAutoFillBackground(True)
        self.blau_6.setStyleSheet("")
        self.blau_6.setText("")
        self.blau_6.setPixmap(QtGui.QPixmap("blau.png"))
        self.blau_6.setWordWrap(False)
        self.blau_6.setObjectName("blau_6")
        self.blau_7 = token_label(self.player1)
        self.blau_7.setGeometry(QtCore.QRect(10, 180, 65, 65))
        self.blau_7.setMaximumSize(QtCore.QSize(100, 100))
        self.blau_7.setAcceptDrops(True)
        self.blau_7.setAutoFillBackground(True)
        self.blau_7.setStyleSheet("")
        self.blau_7.setText("")
        self.blau_7.setPixmap(QtGui.QPixmap("blau.png"))
        self.blau_7.setWordWrap(False)
        self.blau_7.setObjectName("blau_7")
        self.blau_8 = token_label(self.player1)
        self.blau_8.setGeometry(QtCore.QRect(10, 110, 65, 65))
        self.blau_8.setMaximumSize(QtCore.QSize(100, 100))
        self.blau_8.setAcceptDrops(True)
        self.blau_8.setAutoFillBackground(True)
        self.blau_8.setStyleSheet("")
        self.blau_8.setText("")
        self.blau_8.setPixmap(QtGui.QPixmap("blau.png"))
        self.blau_8.setWordWrap(False)
        self.blau_8.setObjectName("blau_8")
        self.blau_9 = token_label(self.player1)
        self.blau_9.setGeometry(QtCore.QRect(10, 40, 65, 65))
        self.blau_9.setMaximumSize(QtCore.QSize(100, 100))
        self.blau_9.setAcceptDrops(True)
        self.blau_9.setAutoFillBackground(True)
        self.blau_9.setStyleSheet("")
        self.blau_9.setText("")
        self.blau_9.setPixmap(QtGui.QPixmap("blau.png"))
        self.blau_9.setWordWrap(False)
        self.blau_9.setObjectName("blau_9")
        self.Sp1_phase = phase(self.player1)
        self.Sp1_phase.setGeometry(QtCore.QRect(10, 730, 57, 15))
        self.Sp1_phase.setStyleSheet("color: rgb(0, 0, 0);")
        self.Sp1_phase.setObjectName("Sp1_phase")
        self.horizontalLayout.addWidget(self.player1)
        spacerItem1 = QtWidgets.QSpacerItem(13, 778,
                                            QtWidgets.QSizePolicy.Minimum,
                                            QtWidgets.QSizePolicy.Expanding)
        self.horizontalLayout.addItem(spacerItem1)

        self.retranslateUi(Dialog)
        self.Reset_pushButton.clicked.connect(Dialog.resetMill)
        QtCore.QMetaObject.connectSlotsByName(Dialog)
Beispiel #9
0
def importPhase(school_id,
                branch_id,
                phase_id,
                session=False,
                username=False,
                password=False):
    try:
        objectList = phaseApi.phase(
            {
                "school_id": school_id,
                "branch_id": branch_id,
                "phase_id": phase_id,
                "username": username,
                "password": password,
            }, session)

        if objectList is None:
            error.log(__file__, False, "Unknown Object")
            return False

        if not "status" in objectList:
            error.log(__file__, False, "Unknown Object")
            return False

        if objectList["status"] == "ok":
            row = objectList["phase"]

            activities = []

            for x in row["activities"]:
                unique = {"activity_id": x["activity_id"]}

                element = {
                    "activity_id": x["activity_id"],
                    "school_id": str(school_id),
                    "branch_id": str(branch_id)
                }

                status = sync.sync(db.events, unique, element)

                activities.append(status["_id"])

                # Launch Activity scraper

            unique = {"phase_id": str(phase_id)}

            team_elements = []

            for x in row["teams"]:
                existsing = db.team_elements.find({
                    "team_element_id":
                    x["team_element_id"]
                }).limit(1)

                if existsing.count() > 0:
                    existsing = existsing[0]
                    team_elements.append(existsing["_id"])

            written = []

            # TODO: Test
            for x in row["assignments"]:
                existsing = db.assignments.find({
                    "title": x["name"],
                    "date": x["date"],
                    "team_elements": {
                        "$in": team_elements
                    }
                }).limit(1)

                data = {"title": x["name"], "date": x["date"]}

                if existsing.count() > 0:
                    existsing = existsing[0]
                    data["exercise_id"] = existsing["exercise_id"]

                written.append(data)

            created = row["created"]

            existsing = db.persons.find({
                "name":
                str(created["teacher"]["name"]),
                "abbrevation":
                str(created["teacher"]["abbrevation"]),
                "branch_id":
                str(branch_id)
            })

            if existsing.count() > 0:
                existsing = existsing[0]

                created["teacher"]["_id"] = existsing["_id"]

            changed = row["changed"]

            existsing = db.persons.find({
                "name":
                str(changed["teacher"]["name"]),
                "abbrevation":
                str(changed["teacher"]["abbrevation"]),
                "branch_id":
                str(branch_id)
            })

            if existsing.count() > 0:
                existsing = existsing[0]

                changed["teacher"]["_id"] = existsing["_id"]

            element = {
                "title": row["title"],
                "phase_id": str(phase_id),
                "school_id": str(school_id),
                "branch_id": str(branch_id),
                "note": row["note"],
                "estimate": row["estimate"],
                "changed": changed,
                "teams": row["teams"],
                "skills": row["focus_points"],
                "work_methods": row["methods"],
                "created": created,
                "periods": row["periods"],
                "activities": activities,
                "written": written
            }

            # Launch Activity Scraper

            status = sync.sync(db.phases, unique, element)

            return True
        else:
            if "error" in objectList:
                error.log(__file__, False, objectList["error"])
                return False
            else:
                error.log(__file__, False, "Unknown error")

    except Exception, e:
        error.log(__file__, False, str(e))
        return False
Beispiel #10
0
    def __init__(self, time_factor, event_output, smart_lights, smart_cars,
                 sim_time):

        self.s = sched.scheduler(time.time, time.sleep)

        #####################################################################
        # INITIALIZE SIMULATION PROPERTIES
        #####################################################################

        self.event_output = event_output
        self.time_factor = time_factor
        self.smart_lights = smart_lights
        self.smart_cars = smart_cars
        self.sim_time = sim_time
        self.auto_cycle_counter = 0

        #####################################################################
        # NORTH AVE / LUCKIE ST COMPONENTS
        #####################################################################
        NAVE_LUCKIE_N_DEP_DISTS = [[1, 0, 0], [0, .5, 1]]
        NAVE_LUCKIE_N_LANES = [
            lane(NAVE_LUCKIE_N_DEP_DISTS[0], self.smart_cars),
            lane(NAVE_LUCKIE_N_DEP_DISTS[1], self.smart_cars)
        ]
        NAVE_LUCKIE_N_ARR_DIST = [4, 1, [.5, .5]]

        NAVE_LUCKIE_E_DEP_DISTS = [[0, 1, 0], [0, .9, 1]]
        NAVE_LUCKIE_E_LANES = [
            lane(NAVE_LUCKIE_E_DEP_DISTS[0], self.smart_cars),
            lane(NAVE_LUCKIE_E_DEP_DISTS[1], self.smart_cars)
        ]
        NAVE_LUCKIE_E_ARR_DIST = [0, 0, [.4, .6]]

        NAVE_LUCKIE_S_DEP_DISTS = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
        NAVE_LUCKIE_S_LANES = [
            lane(NAVE_LUCKIE_S_DEP_DISTS[0], self.smart_cars),
            lane(NAVE_LUCKIE_S_DEP_DISTS[1], self.smart_cars),
            lane(NAVE_LUCKIE_S_DEP_DISTS[2], self.smart_cars)
        ]
        NAVE_LUCKIE_S_ARR_DIST = [4, 1, [.33, .33, .33]]

        NAVE_LUCKIE_W_DEP_DISTS = [[1, 0, 0], [0, 1, 0], [0, .7, 1]]
        NAVE_LUCKIE_W_LANES = [
            lane(NAVE_LUCKIE_W_DEP_DISTS[0], self.smart_cars),
            lane(NAVE_LUCKIE_W_DEP_DISTS[1], self.smart_cars),
            lane(NAVE_LUCKIE_W_DEP_DISTS[2], self.smart_cars)
        ]
        NAVE_LUCKIE_W_ARR_DIST = [18, 2, [.2, .4, .4]]

        NAVE_LUCKIE_N = side("North/Luckie N", NAVE_LUCKIE_N_LANES,
                             NAVE_LUCKIE_N_ARR_DIST, True, self.smart_cars)
        NAVE_LUCKIE_E = side("North/Luckie E", NAVE_LUCKIE_E_LANES,
                             NAVE_LUCKIE_E_ARR_DIST, False, self.smart_cars)
        NAVE_LUCKIE_S = side("North/Luckie S", NAVE_LUCKIE_S_LANES,
                             NAVE_LUCKIE_S_ARR_DIST, True, self.smart_cars)
        NAVE_LUCKIE_W = side("North/Luckie W", NAVE_LUCKIE_W_LANES,
                             NAVE_LUCKIE_W_ARR_DIST, True, self.smart_cars)

        if smart_lights == True:
            NAVE_LUCKIE_PHASES = [
                phase([NAVE_LUCKIE_S], [[0, 1, 2]],
                      10),  #luckie green and arrow
                #luckie green and tech pkwy green
                phase([NAVE_LUCKIE_S, NAVE_LUCKIE_N], [[1, 2], [1]], 10),
                #tech pkwy green and arrow
                phase([NAVE_LUCKIE_N], [[0, 1]], 10),
                #nave west green and arrow
                phase([NAVE_LUCKIE_W], [[0, 1, 2]], 20),
                #nave west green and nave east green
                phase([NAVE_LUCKIE_W, NAVE_LUCKIE_E], [[1, 2], [0, 1]], 75)
            ]
        else:
            NAVE_LUCKIE_PHASES = [
                phase([NAVE_LUCKIE_S], [[0, 1, 2]],
                      15),  #luckie green and arrow
                #luckie green and tech pkwy green
                phase([NAVE_LUCKIE_S, NAVE_LUCKIE_N], [[1, 2], [1]], 15),
                #tech pkwy green and arrow
                phase([NAVE_LUCKIE_N], [[0, 1]], 15),
                #nave west green and arrow
                phase([NAVE_LUCKIE_W], [[0, 1, 2]], 10),
                #nave west green and nave east green
                phase([NAVE_LUCKIE_W, NAVE_LUCKIE_E], [[1, 2], [0, 1]], 65)
            ]

        #####################################################################
        # NORTH AVE / TECHWOOD COMPONENTS
        #####################################################################
        NAVE_TECHWOOD_N_DEP_DISTS = [[1, 0, 0], [0, .7, 1]]
        NAVE_TECHWOOD_N_LANES = [
            lane(NAVE_TECHWOOD_N_DEP_DISTS[0], self.smart_cars),
            lane(NAVE_TECHWOOD_N_DEP_DISTS[1], self.smart_cars)
        ]
        NAVE_TECHWOOD_N_ARR_DIST = [5, 1, [.5, .5]]

        NAVE_TECHWOOD_E_DEP_DISTS = [[1, 0, 0], [0, 1, 0], [0, .8, 1]]
        NAVE_TECHWOOD_E_LANES = [
            lane(NAVE_TECHWOOD_E_DEP_DISTS[0], self.smart_cars),
            lane(NAVE_TECHWOOD_E_DEP_DISTS[1], self.smart_cars),
            lane(NAVE_TECHWOOD_E_DEP_DISTS[2], self.smart_cars)
        ]
        NAVE_TECHWOOD_E_ARR_DIST = [0, 0, [.2, .4, .4]]

        NAVE_TECHWOOD_S_DEP_DISTS = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
        NAVE_TECHWOOD_S_LANES = [
            lane(NAVE_TECHWOOD_S_DEP_DISTS[0], self.smart_cars),
            lane(NAVE_TECHWOOD_S_DEP_DISTS[1], self.smart_cars),
            lane(NAVE_TECHWOOD_S_DEP_DISTS[2], self.smart_cars)
        ]
        NAVE_TECHWOOD_S_ARR_DIST = [2, 1, [.3, .2, .5]]

        NAVE_TECHWOOD_W_DEP_DISTS = [[1, 0, 0], [0, 1, 0], [0, .7, 1]]
        NAVE_TECHWOOD_W_LANES = [
            lane(NAVE_TECHWOOD_W_DEP_DISTS[0], self.smart_cars),
            lane(NAVE_TECHWOOD_W_DEP_DISTS[1], self.smart_cars),
            lane(NAVE_TECHWOOD_W_DEP_DISTS[2], self.smart_cars)
        ]
        NAVE_TECHWOOD_W_ARR_DIST = [0, 0, [.2, .4, .4]]

        NAVE_TECHWOOD_N = side("North/Techwood N", NAVE_TECHWOOD_N_LANES,
                               NAVE_TECHWOOD_N_ARR_DIST, True, self.smart_cars)
        NAVE_TECHWOOD_E = side("North/Techwood E", NAVE_TECHWOOD_E_LANES,
                               NAVE_TECHWOOD_E_ARR_DIST, False,
                               self.smart_cars)
        NAVE_TECHWOOD_S = side("North/Techwood S", NAVE_TECHWOOD_S_LANES,
                               NAVE_TECHWOOD_S_ARR_DIST, True, self.smart_cars)
        NAVE_TECHWOOD_W = side("North/Techwood W", NAVE_TECHWOOD_W_LANES,
                               NAVE_TECHWOOD_W_ARR_DIST, False,
                               self.smart_cars)

        NAVE_TECHWOOD_PHASES = [
            phase([NAVE_TECHWOOD_S], [[0, 1, 2]],
                  10),  #techwood South arrow and green
            #techwood S and Techwood N green
            phase([NAVE_TECHWOOD_S, NAVE_TECHWOOD_N], [[1, 2], [1]], 20),
            #techwood N green and arrow
            phase([NAVE_TECHWOOD_N], [[0, 1]], 10),
            #Nave W green and arrow
            phase([NAVE_TECHWOOD_W], [[0, 1, 2]], 10),
            #Nav W and Nave E Green
            phase([NAVE_TECHWOOD_W, NAVE_TECHWOOD_E], [[1, 2], [1, 2]], 60),
            #Nave E green and arrow
            phase([NAVE_TECHWOOD_E], [[0, 1, 2]], 10)
        ]
        NAVE_TECHWOOD_N = side("North/Techwood N", NAVE_TECHWOOD_N_LANES,
                               NAVE_TECHWOOD_N_ARR_DIST, True, self.smart_cars)
        NAVE_TECHWOOD_E = side("North/Techwood E", NAVE_TECHWOOD_E_LANES,
                               NAVE_TECHWOOD_E_ARR_DIST, False,
                               self.smart_cars)
        NAVE_TECHWOOD_S = side("North/Techwood S", NAVE_TECHWOOD_S_LANES,
                               NAVE_TECHWOOD_S_ARR_DIST, True, self.smart_cars)
        NAVE_TECHWOOD_W = side("North/Techwood W", NAVE_TECHWOOD_W_LANES,
                               NAVE_TECHWOOD_W_ARR_DIST, False,
                               self.smart_cars)

        if smart_lights == True:
            NAVE_TECHWOOD_PHASES = [
                phase([NAVE_TECHWOOD_S], [[0, 1, 2]],
                      5),  #techwood South arrow and green
                #techwood S and Techwood N green
                phase([NAVE_TECHWOOD_S, NAVE_TECHWOOD_N], [[1, 2], [1]], 10),
                #techwood N green and arrow
                phase([NAVE_TECHWOOD_N], [[0, 1]], 5),
                #Nave W green and arrow
                phase([NAVE_TECHWOOD_W], [[0, 1, 2]], 15),
                #Nav W and Nave E Green
                phase([NAVE_TECHWOOD_W, NAVE_TECHWOOD_E], [[1, 2], [1, 2]],
                      70),
                #Nave E green and arrow
                phase([NAVE_TECHWOOD_E], [[0, 1, 2]], 15)
            ]
        else:
            NAVE_TECHWOOD_PHASES = [
                phase([NAVE_TECHWOOD_S], [[0, 1, 2]],
                      10),  #techwood South arrow and green
                #techwood S and Techwood N green
                phase([NAVE_TECHWOOD_S, NAVE_TECHWOOD_N], [[1, 2], [1]], 20),
                #techwood N green and arrow
                phase([NAVE_TECHWOOD_N], [[0, 1]], 10),
                #Nave W green and arrow
                phase([NAVE_TECHWOOD_W], [[0, 1, 2]], 10),
                #Nav W and Nave E Green
                phase([NAVE_TECHWOOD_W, NAVE_TECHWOOD_E], [[1, 2], [1, 2]],
                      60),
                #Nave E green and arrow
                phase([NAVE_TECHWOOD_E], [[0, 1, 2]], 10)
            ]

        #####################################################################
        # OFFRAMP COMPONENTS
        #####################################################################
        OFFRAMP_249_DEP_DISTS = [[1, 0, 0], [0.5, 0, 1]]
        OFFRAMP_249_LANES = [
            lane(OFFRAMP_249_DEP_DISTS[0], self.smart_cars),
            lane(OFFRAMP_249_DEP_DISTS[1], self.smart_cars)
        ]
        OFFRAMP_249_ARR_DIST = [6, 1, [0.5, 0.5]]

        OFFRAMP_WEST_DEP_DIST = [[0, 1, 0], [0, 1, 0]]
        OFFRAMP_WEST_LANES = [
            lane(OFFRAMP_WEST_DEP_DIST[0], self.smart_cars),
            lane(OFFRAMP_WEST_DEP_DIST[1], self.smart_cars)
        ]
        OFFRAMP_WEST_ARR_DIST = [0, 0, [0.5, 0.5]]

        OFFRAMP_EAST_DEP_DIST = [[0, 1, 0], [0, 1, 0]]
        OFFRAMP_EAST_LANES = [
            lane(OFFRAMP_EAST_DEP_DIST[0], self.smart_cars),
            lane(OFFRAMP_EAST_DEP_DIST[1], self.smart_cars)
        ]
        OFFRAMP_EAST_ARR_DIST = [16, 2, [0.5, 0.5]]

        OFFRAMP_249 = side("Offramp 249", OFFRAMP_249_LANES,
                           OFFRAMP_249_ARR_DIST, True, self.smart_cars)
        OFFRAMP_WEST = side("Offramp West", OFFRAMP_WEST_LANES,
                            OFFRAMP_WEST_ARR_DIST, False, self.smart_cars)
        OFFRAMP_EAST = side("Offramp East", OFFRAMP_EAST_LANES,
                            OFFRAMP_EAST_ARR_DIST, True, self.smart_cars)

        if smart_lights == True:
            OFFRAMP_PHASES = [
                phase([OFFRAMP_WEST, OFFRAMP_EAST], [[0, 1], [0, 1]],
                      60),  #Nave e and Nave w green light
                #off-ramp green lights
                phase([OFFRAMP_249], [[0, 1]], 15)
            ]
        else:
            OFFRAMP_PHASES = [
                phase([OFFRAMP_WEST, OFFRAMP_EAST], [[0, 1], [0, 1]],
                      40),  #Nave e and Nave w green light
                #off-ramp green lights
                phase([OFFRAMP_249], [[0, 1]], 20)
            ]

        #####################################################################
        # INTERSECTION OBJECTS
        #####################################################################
        nave_luckie = intersection(
            self.s, "North/Luckie",
            [NAVE_LUCKIE_N, NAVE_LUCKIE_E, NAVE_LUCKIE_S, NAVE_LUCKIE_W],
            NAVE_LUCKIE_PHASES)
        nave_techwood = intersection(self.s, "North/Techwood", [
            NAVE_TECHWOOD_N, NAVE_TECHWOOD_E, NAVE_TECHWOOD_S, NAVE_TECHWOOD_W
        ], NAVE_TECHWOOD_PHASES)
        offramp = intersection(self.s, "Offramp",
                               [OFFRAMP_249, OFFRAMP_EAST, OFFRAMP_WEST],
                               OFFRAMP_PHASES)

        # interconnect them by setting destinations
        nave_luckie.sides[0].set_dests([nave_techwood.sides[3], None, None])
        nave_luckie.sides[2].set_dests([None, None, nave_techwood.sides[3]])
        nave_luckie.sides[3].set_dests([None, nave_techwood.sides[3], None])
        nave_techwood.sides[0].set_dests(
            [offramp.sides[2], None, nave_luckie.sides[1]])
        nave_techwood.sides[1].set_dests([None, nave_luckie.sides[1], None])
        nave_techwood.sides[2].set_dests(
            [nave_luckie.sides[1], None, offramp.sides[2]])
        nave_techwood.sides[3].set_dests([None, offramp.sides[2], None])
        offramp.sides[0].set_dests([None, None, nave_techwood.sides[1]])
        offramp.sides[1].set_dests([None, nave_techwood.sides[1], None])
        offramp.sides[2].set_dests([None, None, None])

        intersections = [nave_luckie, nave_techwood, offramp]
        self.intersections = intersections
Beispiel #11
0
    def __init__(self, info_dict, fwk, index):
        """
        construct and manage the workflow of a simulation and its constituent components
        """

        # stuff from the framework
        self.RM = fwk.RM
        self.fwk = fwk

        # bookkeeping
        self.total_usage = 0
        self.total_work_time = 0
        self.total_lost_time = 0
        self.total_overhead = 0
        self.total_restart_time = 0
        self.total_resubmit_time = 0
        self.total_launch_delay = 0
        self.total_rework_time = 0
        self.total_ckpt_time = 0
        self.total_waiting_time = 0
        self.num_waiting = 0
        self.num_restarts = 0
        self.num_rework = 0
        self.num_work = 0
        self.num_ckpts = 0
        self.num_faults = 0
        self.num_retries = 0
        self.resubmissions = 0
        self.last_submission_time = 0

        # my components and properties
        self.state = 'startup'  # other states: 'shutdown', 'checkpoint', 'restart', 'work'
        self.my_comps = dict()
        self.all_comps = dict()
        self.my_overheads = dict()
        self.phases = dict()
        self.is_done = False
        self.resubmission_threshold = 5
        try:
            self.name = info_dict['name'] + '_' + str(index)
        except:
            raise

        try:
            self.mode = info_dict['mode']
        except:
            self.mode = 'normal'  # this means time stepped

        if self.mode == 'normal':
            self.fwk.failure_mode = 'normal'
            try:
                self.nsteps = int(info_dict['nsteps'])
                self.comp_list = info_dict['components']
            except:
                self.nsteps = 0
                self.comp_list = []

            try:
                self.phase_list = info_dict['phases']
            except:
                self.phase_list = []

            if self.nsteps > 0 and self.comp_list:
                self.old_style = True
            elif self.phase_list:
                self.old_style = False
            else:
                print "bad config file"
                raise

            try:
                self.ft_strategy = info_dict['ft_strategy']
            except:
                self.ft_strategy = None

            try:
                self.retry_limit = int(info_dict['retry_limit'])
            except:
                self.retry_limit = -1

            self.curr_step = 1
            self.curr_phase_index = -1
            self.curr_phase = ''
            self.total_steps = 0

        elif self.mode == 'total_time':
            #self.fwk.failures_on = True
            self.fwk.failure_mode = 'sandia'
            try:
                self.total_work = int(info_dict['total_work'])
                self.comp_list = info_dict['components']
            except:
                raise
            self.rework_todo = 0
            self.completed_work = 0
            self.old_style = True

        # get overheads
        try:
            startup = info_dict['startup']
            self.my_overheads.update({
                'startup':
                overhead(None, self.fwk, self, None, 'startup', startup)
            })
        except:
            self.my_overheads.update({
                'startup':
                overhead(None, self.fwk, self, None, 'startup', None)
            })

        try:
            resubmit = info_dict['resubmit']
            self.my_overheads.update({
                'resubmit':
                overhead(None, self.fwk, self, None, 'resubmit', resubmit)
            })
        except:
            self.my_overheads.update({
                'resubmit':
                overhead(None, self.fwk, self, None, 'resubmit', None)
            })

        try:
            shutdown = info_dict['shutdown']
            self.my_overheads.update({
                'shutdown':
                overhead(None, self.fwk, self, None, 'shutdown', shutdown)
            })
        except:
            self.my_overheads.update({
                'shutdown':
                overhead(None, self.fwk, self, None, 'shutdown', None)
            })

        try:
            restart = info_dict['restart']
            self.my_overheads.update({
                'restart':
                overhead(None, self.fwk, self, None, 'restart', restart)
            })
        except:
            self.my_overheads.update({
                'restart':
                overhead(None, self.fwk, self, None, 'restart', None)
            })

        try:
            launch_delay = info_dict['launch_delay']
            self.my_overheads.update({
                'launch_delay':
                overhead(None, self.fwk, self, None, 'launch_delay',
                         launch_delay)
            })
        except:
            self.my_overheads.update({
                'launch_delay':
                overhead(None, self.fwk, self, None, 'launch_delay', None)
            })

        # is checkpointing being modeled?
        try:
            ckpt_section = info_dict['checkpoint']
            ckpt_on_val = ckpt_section['ckpt_on']
            if ckpt_on_val == 'True':
                self.ckpt_on = True
            else:
                self.ckpt_on = False
        except:
            self.ckpt_on = False

        # get checkpointing parameters
        if self.ckpt_on:
            try:
                self.ckpt_mode = ckpt_section['ckpt_mode']
                if self.ckpt_mode == 'sandia':
                    self.last_ckpt = 0
                    try:
                        self.next_ckpt = int(ckpt_section['tau'])
                        self.ckpt_interval = self.next_ckpt
                    except:
                        # **** NEED TO CHANGE TO CALCULATE INITIAL VAL!!!!
                        self.next_ckpt = 10
                elif self.ckpt_mode == 'wall_regular' or self.ckpt_mode == 'phys_regular':
                    self.ckpt_interval = int(ckpt_section['ckpt_interval'])
                    self.next_ckpt = self.ckpt_interval
                elif self.ckpt_mode == 'wall_explicit' or self.ckpt_mode == 'phys_explicit':
                    self.ckpt_values = [
                        int(x) for x in ckpt_section['ckpt_values']
                    ]
                    self.next_ckpt = self.ckpt_values.pop(0)
                self.my_overheads.update({
                    'checkpoint':
                    overhead(None, self.fwk, self, None, 'checkpoint',
                             ckpt_section)
                })
            except:
                print "problems setting up checkpoint parameters"
                raise
        self.ckpt_comps = list()
        self.ckpt_step = 0
        self.ckpt_phase_index = 0
        self.ckpt_phase = ''

        # add components
        try:
            if self.mode == 'total_time':
                self.phase_list.append('none')
                self.phases.update({
                    'none':
                    phase({}, self.fwk, self, 'none', old_style=True)
                })
                self.phases['none'].comp_list = self.comp_list
                if not isinstance(self.comp_list, list):
                    self.comp_list = [self.comp_list]
                for s in self.comp_list:
                    self.all_comps.update({
                        'none_' + s:
                        component(info_dict[s], self.fwk, self, 'none')
                    })
            elif self.old_style:
                self.phase_list.append('none')
                self.phases.update({
                    'none':
                    phase({}, self.fwk, self, 'none', old_style=True)
                })
                self.phases['none'].nsteps = self.nsteps
                self.phases['none'].comp_list = self.comp_list
                if not isinstance(self.comp_list, list):
                    self.comp_list = [self.comp_list]
                for s in self.comp_list:
                    self.all_comps.update({
                        'none_' + s:
                        component(info_dict[s], self.fwk, self, 'none')
                    })
            else:
                if not isinstance(self.phase_list, list):
                    self.phase_list.append(self.phase_list)
                for p in self.phase_list:
                    self.phases.update(
                        {p: phase(info_dict[p], self.fwk, self.name, p)})
                    if not isinstance(self.phases[p].comp_list, list):
                        self.phases[p].comp_list = [self.phases[p].comp_list]
                    for s in self.phases[p].comp_list:
                        self.all_comps.update({
                            p + '_' + s:
                            component(info_dict[p][s], self.fwk, self, p)
                        })
        except:
            raise

        if self.fwk.debug:
            for k, v in self.phases.items():
                print "phase:", k, "nsteps:", v.nsteps, "comps:", v.comp_list
                for c in self.all_comps.values():
                    print c.name, c.nproc, c.runtime, c.stddev
        self.get_next_phase()

        # populate handles to total_time components
        if self.mode == 'total_time':
            for c in self.my_comps.values():
                if c.type == 'sandia_work':
                    self.work_comp = c
                    self.work_comp.state = "ready"
                elif c.type == 'sandia_rework':
                    self.rework_comp = c
                elif c.type == 'sandia_restart':
                    self.restart_comp = c
                elif c.type == 'sandia_ckpt':
                    self.ckpt_comp = c

        #self.get_ready_comps()
        if self.fwk.debug:
            print self.my_comps.keys()
Beispiel #12
0
def every_minute():
    # Sets timer to run code again in 60 seconds
    threading.Timer(60, every_minute).start()

    # Record date and time
    timestamp = datetime.datetime.now()
    print(timestamp)

    # Record light data from si1145 sensor
    [vis, IR, uvIndex] = si1145.si()

    print("Visible light: %d lx" % vis)
    print("IR light: %d lx" % IR)
    print("UV index: %.2f" % uvIndex)

    # Record temperature, humidity, & pressure from bme280 sensor
    [temp, humid, press] = bme280.bme()

    print("Temperature: %.2f deg F" % temp)
    print("Humidity: %.2f %%" % humid)
    print("Pressure: %.2f hPa" % press)

    # Record eCO2 and TVOC from sgp30 sensor
    [eCO2, TVOC] = sgp30.sgp()

    print("CO2eq: %.2f ppm" % eCO2)
    print("TVOC: %.2f ppb" % TVOC)

    # Record raw ADC voltage values to determine unscaled RMS values. These functions run for 5 seconds each by default
    Vrms_unscaled = ads1015_mod.vrms()
    Irms_unscaled = ads1015_mod.irms()

    # Record phase angle and frequency values. This function runs for 5 seconds by default
    [theta, freq] = phase.phase()

    # Calculate real power, reactive power, power factor, and power factor lead/lag status
    [P, Q, S, pf, pfstatus] = power.power(Vrms_unscaled, Irms_unscaled, freq,
                                          theta)

    theta_d = theta * 180 / 3.1415927
    print("P: %.2f W" % P)
    print("Q: %.2f VAr" % Q)
    print("S: %.2f VA" % S)
    print("Power Factor is %f %s" % (pf, pfstatus))
    print("Theta: %f deg" % theta_d)
    print("Freq: %f Hz" % freq)

    # Record wind speed. This function runs for 20 seconds by default
    #anemo.t_run = 2 #uncomment to speed up testing
    wind_speed = anemo.anemo()
    [wind_direction, wind_angle] = ads1015_mod.getdirection()

    print("Wind speed: %f" % wind_speed)
    print("Wind direction: %s" % wind_direction)

    # Record precipation rate. This function runs for 20 seconds by default
    #precip.t_run = 2 #uncomment to speed up testing
    precip_rate = precip.precip()

    print("Precip rate: %f\n" % precip_rate)

    # Send data to database
    global client

    # Influx
    json_body = [{
        "measurement": "Light",
        "tags": {
            "host": "server01",
            "region": "us-east"
        },
        "time": timestamp.strftime("%Y-%m-%dT%H:%M:%S"),
        "fields": {
            "value": vis
        }
    }, {
        "measurement": "IR",
        "tags": {
            "host": "server01",
            "region": "us-east"
        },
        "time": timestamp.strftime("%Y-%m-%dT%H:%M:%S"),
        "fields": {
            "value": IR
        }
    }, {
        "measurement": "uvIndex",
        "tags": {
            "host": "server01",
            "region": "us-east"
        },
        "time": timestamp.strftime("%Y-%m-%dT%H:%M:%S"),
        "fields": {
            "value": uvIndex
        }
    }, {
        "measurement": "temp",
        "tags": {
            "host": "server01",
            "region": "us-east"
        },
        "time": timestamp.strftime("%Y-%m-%dT%H:%M:%S"),
        "fields": {
            "value": temp
        }
    }, {
        "measurement": "humid",
        "tags": {
            "host": "server01",
            "region": "us-east"
        },
        "time": timestamp.strftime("%Y-%m-%dT%H:%M:%S"),
        "fields": {
            "value": humid
        }
    }, {
        "measurement": "press",
        "tags": {
            "host": "server01",
            "region": "us-east"
        },
        "time": timestamp.strftime("%Y-%m-%dT%H:%M:%S"),
        "fields": {
            "value": press
        }
    }, {
        "measurement": "eCO2",
        "tags": {
            "host": "server01",
            "region": "us-east"
        },
        "time": timestamp.strftime("%Y-%m-%dT%H:%M:%S"),
        "fields": {
            "value": eCO2
        }
    }, {
        "measurement": "TVOC",
        "tags": {
            "host": "server01",
            "region": "us-east"
        },
        "time": timestamp.strftime("%Y-%m-%dT%H:%M:%S"),
        "fields": {
            "value": TVOC
        }
    }, {
        "measurement": "P",
        "tags": {
            "host": "server01",
            "region": "us-east"
        },
        "time": timestamp.strftime("%Y-%m-%dT%H:%M:%S"),
        "fields": {
            "value": P
        }
    }, {
        "measurement": "Q",
        "tags": {
            "host": "server01",
            "region": "us-east"
        },
        "time": timestamp.strftime("%Y-%m-%dT%H:%M:%S"),
        "fields": {
            "value": Q
        }
    }, {
        "measurement": "pfstatus",
        "tags": {
            "host": "server01",
            "region": "us-east"
        },
        "time": timestamp.strftime("%Y-%m-%dT%H:%M:%S"),
        "fields": {
            "value": pfstatus
        }
    }, {
        "measurement": "wind_speed",
        "tags": {
            "host": "server01",
            "region": "us-east"
        },
        "time": timestamp.strftime("%Y-%m-%dT%H:%M:%S"),
        "fields": {
            "value": wind_speed
        }
    }, {
        "measurement": "wind_direction",
        "tags": {
            "host": "server01",
            "region": "us-east"
        },
        "time": timestamp.strftime("%Y-%m-%dT%H:%M:%S"),
        "fields": {
            "value": wind_direction
        }
    }, {
        "measurement": "wind_angle",
        "tags": {
            "host": "server01",
            "region": "us-east"
        },
        "time": timestamp.strftime("%Y-%m-%dT%H:%M:%S"),
        "fields": {
            "value": wind_angle
        }
    }, {
        "measurement": "precip_rate",
        "tags": {
            "host": "server01",
            "region": "us-east"
        },
        "time": timestamp.strftime("%Y-%m-%dT%H:%M:%S"),
        "fields": {
            "value": precip_rate
        }
    }]

    client.write_points(json_body)
Beispiel #13
0
def importPhase ( school_id, branch_id, phase_id, session = False, username = False, password = False ):
	try:
		objectList = phaseApi.phase({
			"school_id" : school_id,
			"branch_id" : branch_id,
			"phase_id" : phase_id,
			"username" : username,
			"password" : password,
		}, session)

		if objectList is None:
				error.log(__file__, False, "Unknown Object")
				return False

		if not "status" in objectList:
			error.log(__file__, False, "Unknown Object")
			return False

		if objectList["status"] == "ok":
			row = objectList["phase"]

			activities = []

			for x in row["activities"]:
				unique = {
					"activity_id" : x["activity_id"]
				}

				element = {
					"activity_id" : x["activity_id"],
					"school_id" : str(school_id),
					"branch_id" : str(branch_id)
				}

				status = sync.sync(db.events, unique, element)

				activities.append(status["_id"])

				# Launch Activity scraper

			unique = {
				"phase_id" : str(phase_id)
			}

			team_elements = []

			for x in row["teams"]:
				existsing = db.team_elements.find({"team_element_id" : x["team_element_id"]}).limit(1)

				if existsing.count() > 0:
					existsing = existsing[0]
					team_elements.append(existsing["_id"])

			written = []

			# TODO: Test
			for x in row["assignments"]:
				existsing = db.assignments.find({"title" : x["name"], "date" : x["date"], "team_elements" : { "$in" : team_elements}}).limit(1)

				data = {
					"title" : x["name"],
					"date" : x["date"]
				}

				if existsing.count() > 0:
					existsing = existsing[0]
					data["exercise_id"] = existsing["exercise_id"]

				written.append(data)

			created = row["created"]

			existsing = db.persons.find({"name" : str(created["teacher"]["name"]), "abbrevation" : str(created["teacher"]["abbrevation"]), "branch_id" : str(branch_id)})

			if existsing.count() > 0:
				existsing = existsing[0]

				created["teacher"]["_id"] = existsing["_id"]

			changed = row["changed"]

			existsing = db.persons.find({"name" : str(changed["teacher"]["name"]), "abbrevation" : str(changed["teacher"]["abbrevation"]), "branch_id" : str(branch_id)})

			if existsing.count() > 0:
				existsing = existsing[0]

				changed["teacher"]["_id"] = existsing["_id"]

			element = {
				"title" : row["title"],
				"phase_id" : str(phase_id),
				"school_id" : str(school_id),
				"branch_id" : str(branch_id),
				"note" : row["note"],
				"estimate" : row["estimate"],
				"changed" : changed,
				"teams" : row["teams"],
				"skills" : row["focus_points"],
				"work_methods" : row["methods"],
				"created" : created,
				"periods" : row["periods"],
				"activities" : activities,
				"written" : written
			}

			# Launch Activity Scraper

			status = sync.sync(db.phases, unique, element)

			return True
		else:
			if "error" in objectList:
				error.log(__file__, False, objectList["error"])
				return False
			else:
				error.log(__file__, False, "Unknown error")

	except Exception, e:
		error.log(__file__, False, str(e))
		return False