Exemplo n.º 1
0
    def _get_app_timeline(self, store, app, reverse=False):
        usage_stats = store.query_catalog(Catalog.CATALOG_LOGS,
                                          "usage_stats.usage_stats")
        if usage_stats == None: return None

        time_stats = {}
        for stat in usage_stats.subsection_items:
            name = stat.get_subvaluebyname("activity_name")
            if name.startswith(app.name) == False: continue
            time = stat.get_subvaluebyname("last_run")
            if type(time) != int:
                if time.isdigit() == False:
                    print "Non-digit timestamp??"
                    continue
                time = int(time)
            if time in time_stats:
                time_stats[time].append(name)
            else:
                time_stats[time] = [name]

        sorted_keys = sorted(time_stats.keys(), reverse=reverse)

        timeline = Timeline()
        for key in sorted_keys:
            for stat in time_stats[key]:
                timeline.add_item(TimelineItem(stat, "fa-sliders", key))

        timeline_items = timeline.get_items()
        if len(timeline_items) == 0: return None
        return timeline_items
Exemplo n.º 2
0
 def _get_app_timeline(self, store, app, reverse=False):
     usage_stats = store.query_catalog( Catalog.CATALOG_LOGS, 
                                        "usage_stats.usage_stats" )
     if usage_stats == None: return None
     
     time_stats = {}
     for stat in usage_stats.subsection_items:
         name = stat.get_subvaluebyname("activity_name")
         if name.startswith(app.name) == False: continue
         time = stat.get_subvaluebyname("last_run")
         if type(time) != int:
             if time.isdigit() == False:
                 print "Non-digit timestamp??"
                 continue
             time = int(time)
         if time in time_stats:
             time_stats[time].append( name )
         else:
             time_stats[time] = [name]
     
     sorted_keys = sorted(time_stats.keys(), reverse=reverse)
     
     timeline = Timeline()
     for key in sorted_keys:
         for stat in time_stats[key]:
             timeline.add_item( TimelineItem( stat, "fa-sliders", key ) )
     
     timeline_items = timeline.get_items()
     if len(timeline_items) == 0: return None
     return timeline_items
Exemplo n.º 3
0
 def reset_running_clock(self, *args):
     if self.ui_state == UI_STATE.RUNNING_CLOCK:
         return
     self.ui_state = UI_STATE.RUNNING_CLOCK
     self.state.reset_running_clock()
     clock = self.state.running_clock.to_timer_clock(self.state.now)
     self.reset_and_show_notify(
         "Timer is set.", "Count down {}.\nNotify at {}".format(
             clock.to_timer_clock(self.state.now),
             clock.to_alarm_clock(self.state.now)))
     self.alarm_timeline = Timeline(
         self.generate_alarm_timeline(clock.duration))
     self.alarm_timeline.start()
Exemplo n.º 4
0
    def parse(self, node):
        self.id = int(node.attrib['id'])
        self.name = node.attrib['name']
        self.length_ms = float(node.attrib['length'])
        self.length = self.length_ms / 1000.0

        self.loop = node.attrib.get('looping', 'true') != 'false'

        for elem in node:
            if elem.tag == 'mainline':
                self.parse_mainline(elem)
            elif elem.tag == 'timeline':
                t = Timeline(elem)
                self.timeline[t.get_id()] = t
Exemplo n.º 5
0
    def parse(self, node):
        self.id = int(node.attrib['id'])
        self.name = node.attrib['name']
        self.length_ms = float(node.attrib['length'])
        self.length = self.length_ms / 1000.0

        self.loop = node.attrib.get('looping', 'true') != 'false'

        for elem in node:
            if elem.tag == 'mainline':
                self.parse_mainline(elem)
            elif elem.tag == 'timeline':
                t = Timeline(elem)
                self.timeline[t.get_id()] = t
Exemplo n.º 6
0
 def __init__(self):
     self.lightBoard = self.makeLightBoard()
     self.ableton = Ableton()
     self.timeline = Timeline()
     self.filterMin = 60
     self.filterMax = 135
     self.houseLights = [
         1, 2, 3, 4, 5, 6, 11, 12, 13, 14, 15, 16, 17, 18, 22
     ]
     self.sideRight = [11, 12, 13, 14]
     self.allLightsUsed = [2, 11, 12, 15, 16, 25]
     self.allLightsUsedExceptChannelTwo = [11, 12, 15, 16, 25]
     self.lightNormal = 75
     self.lightMin = 0
     self.lightMax = 100
     self.startPerformance()
Exemplo n.º 7
0
def simulation(start_day=4, start_hour=8, duration_in_days=14 + 7 / 24, seed=3):
    """Runs full simulation and returns log"""
    lambdas_vec_weekday, lambdas_vec_weekend, behaviour_freqs, user_behaviour_df, df, prior_a, prior_b, action_time_vec\
        = preprocess()
    np.random.seed(seed)
    sim_log = []
    timeline = Timeline(lambdas_vec_weekend, lambdas_vec_weekday, start_day=start_day, duration_in_days=duration_in_days, start_hour=start_hour)
    timeline.simulate_server_init_times()

    for (i, time) in enumerate(timeline.server_init_times):
        user = User(i, time, behaviour_freqs, user_behaviour_df, df, prior_a, prior_b, action_time_vec)
        user.interact()
        sim_log += user.log

    sim_log_df = pd.DataFrame(sim_log, columns=['uId', 'storeId', 'action', 'eventTime']).sort_values('eventTime')

    sim_log_df.to_csv('simulation_results.csv')
Exemplo n.º 8
0
class App:
    def __init__(self):
        self.state = AppState()
        self.ui_state = None
        self.indicator_menu = ForceBreakIndicatorMenu()
        self.indicator = AppIndicator3.Indicator.new(
            APP_NAME,
            "system-run",  # this is just a placeholder
            AppIndicator3.IndicatorCategory.APPLICATION_STATUS)
        self.binds_indicator_menu_state(self.indicator_menu)
        self.alarm_timeline = None
        self.__countdown_notify = Notify.Notification.new("")
        self.__countdown_notify.set_urgency(Notify.Urgency.CRITICAL)
        self.__countdown_notify.set_timeout(3000)

    def update_now_periodically(self, interval_ms: int = 500):
        def timeout_callback():
            self.state.reset_now()
            return True

        return GLib.timeout_add(interval_ms, timeout_callback)

    def new_app_window(self):
        win = AppWindow()
        self.binds_window_state(win)
        return win

    def binds_indicator_menu_state(self, indicator_menu):
        self.state.bind_property('now', indicator_menu, 'now',
                                 GObject.BindingFlags.SYNC_CREATE)
        self.state.bind_property('running_clock', indicator_menu,
                                 'running_clock',
                                 GObject.BindingFlags.SYNC_CREATE)

        indicator_menu.connect('reset-clock-activated', self.pick_new_clock)
        indicator_menu.connect('quit-activated', self.ask_quit)

    def binds_window_state(self, window):
        self.state.bind_property(
            'picked_clock', window, 'picking_clock',
            GObject.BindingFlags.BIDIRECTIONAL
            | GObject.BindingFlags.SYNC_CREATE)
        self.state.bind_property('now', window, 'now',
                                 GObject.BindingFlags.SYNC_CREATE)

        window.connect('quit', self.ask_quit)
        window.connect('clock-picked', self.reset_running_clock)
        window.connect('clock-picked', lambda *args: window.close())

    def reset_running_clock(self, *args):
        if self.ui_state == UI_STATE.RUNNING_CLOCK:
            return
        self.ui_state = UI_STATE.RUNNING_CLOCK
        self.state.reset_running_clock()
        clock = self.state.running_clock.to_timer_clock(self.state.now)
        self.reset_and_show_notify(
            "Timer is set.", "Count down {}.\nNotify at {}".format(
                clock.to_timer_clock(self.state.now),
                clock.to_alarm_clock(self.state.now)))
        self.alarm_timeline = Timeline(
            self.generate_alarm_timeline(clock.duration))
        self.alarm_timeline.start()

    def pick_new_clock(self, *args):
        if self.ui_state == UI_STATE.PICKING_CLOCK:
            return
        self.ui_state = UI_STATE.PICKING_CLOCK
        self.state.remove_running_clock()
        win = self.new_app_window()
        win.show_all()
        win.fullscreen()
        win.present()
        if self.alarm_timeline is not None:
            self.alarm_timeline.stop()

    def show_indicator(self):
        self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE)
        self.indicator.set_menu(self.indicator_menu)

    def generate_alarm_timeline(self, duration: timedelta):
        res = []
        res.append(self.pick_new_clock)
        one_sec = timedelta(seconds=1)

        for countdown in range(1, 4):
            if duration < one_sec:
                break
            duration -= one_sec
            res.append(1000)
            res.append(
                partial(self.reset_and_show_notify,
                        "Timer ends in " + str(countdown)))
        res.append(int(duration.total_seconds() * 1000))
        return reversed(res)

    def reset_and_show_notify(self, summary, body=None):
        self.__countdown_notify.update(summary, body)
        self.__countdown_notify.show()

    def ask_quit(self, parent, *args):
        dialog = Gtk.Dialog(
            parent=parent if isinstance(parent, Gtk.Window) else None)
        dialog.get_content_area().set_center_widget(
            Gtk.Label(label="Do you really want to quit?", margin=10))
        dialog.add_button("Yes", 1)
        dialog.add_button("No", 2)
        dialog.set_default_response(2)
        dialog.show_all()
        if dialog.run() == 1:
            finalize()
        else:
            dialog.close()
Exemplo n.º 9
0
 def create_timeline(self):
     self.timeline = Timeline()
     return self.timeline
Exemplo n.º 10
0
class App:
    def __init__(self):
        self.lightBoard = self.makeLightBoard()
        self.ableton = Ableton()
        self.timeline = Timeline()
        self.filterMin = 60
        self.filterMax = 135
        self.houseLights = [
            1, 2, 3, 4, 5, 6, 11, 12, 13, 14, 15, 16, 17, 18, 22
        ]
        self.sideRight = [11, 12, 13, 14]
        self.allLightsUsed = [2, 11, 12, 15, 16, 25]
        self.allLightsUsedExceptChannelTwo = [11, 12, 15, 16, 25]
        self.lightNormal = 75
        self.lightMin = 0
        self.lightMax = 100
        self.startPerformance()

    def makeLightBoard(self):
        lightBoardEnviron = os.environ['LIGHTBOARD']
        if lightBoardEnviron == 'DMX':
            return DmxLightBoard('port')
        elif lightBoardEnviron == 'EtcElement':
            return EtcElement('169.254.1.42', 3000)
        raise Exception('Set LIGHTBOARD environ to DMX or EtcElement')

    def update(self):
        self.ableton.update()
        self.timeline.update()
        self.lightBoard.update()
        time.sleep(0.1)

    def startPerformance(self):
        self.performanceRunning = True
        self.ableton.play()
        self.ableton.waitForNextBeat()
        self.ableton.stopClip('muffle', 'fumbling around')
        self.ableton.stopClip('piano treble drone', 'piano treble drone 1')
        self.ableton.stopClip('guitar', 'guitar 2')
        self.ableton.stopClip('wavetable', '1')
        self.ableton.stopClip('wavetable', '2')
        self.ableton.stopClip('wavetable', '3')
        self.ableton.stopClip('wavetable', '4')
        self.ableton.stopClip('wavetable', '5')
        self.ableton.stopClip('grand piano', '1')
        self.ableton.stopClip('grand piano', '2')
        self.ableton.stopClip('grand piano', '3')
        self.ableton.stopClip('grand piano', '4')
        self.ableton.stopClip('grand piano', '5')
        self.ableton.stopClip('piano bass drone', 'piano bass drone 1')
        self.ableton.stopClip('guitar drones', 'guitar drone uplifting')
        self.ableton.stopClip('violin', 'violin forward')
        self.ableton.setParameter('Master', 'Auto Filter', 'Frequency', 135)
        violin = self.ableton.getTrack('violin')
        violin.get_device('Simple Delay').enabled = False
        violin.get_device('Ping Pong Delay').enabled = False
        violin.get_device('Ping Pong Delay').get_parameter_by_name(
            'Freeze').value = 0
        self.ableton.getTrack('guitar drones').volume = 0
        self.ableton.getTrack('guitar drones').mute = 0
        self.lightBoard.blackout()
        self.ableton.playClip('muffle', 'fumbling around')
        self.ableton.playClip('grand piano', '1')
        self.ableton.playClip('wavetable', '1')
        self.timeline.cueInSeconds(
            1,
            lambdaFunction=lambda: self.ableton.playClip(
                'guitar drones', 'guitar drone uplifting'))
        self.timeline.cueInSeconds(1,
                                   action=self.fadeLights(
                                       self.allLightsUsed, 60.0,
                                       self.lightBoard.lightMin,
                                       self.lightBoard.lightMax))
        self.timeline.cueInSeconds(1,
                                   action=self.fadeVolume(
                                       self.ableton.getTrack('guitar drones'),
                                       60, 0, 0.7))
        self.timeline.cueInSeconds(
            30,
            lambdaFunction=lambda: self.ableton.playClip(
                'piano treble drone', 'piano treble drone 1'))
        self.timeline.cueInSeconds(
            1 * 60, lambdaFunction=lambda: self.executeTransition0())
        self.timeline.cueInSeconds(
            2 * 60, lambdaFunction=lambda: self.executeTransition1())
        self.timeline.cueInSeconds(
            3 * 60, lambdaFunction=lambda: self.executeTransition2())
        self.timeline.cueInSeconds(
            4 * 60, lambdaFunction=lambda: self.executeTransition3())
        self.timeline.cueInSeconds(
            5 * 60, lambdaFunction=lambda: self.executeTransition4())

    def executeTransition0(self):
        self.ableton.playClip('grand piano', '2')
        self.ableton.playClip('wavetable', '2')

    def executeTransition1(self):
        self.ableton.playClip('guitar', 'guitar 2')
        self.ableton.playClip('piano bass drone', 'piano bass drone 1')
        self.ableton.playClip('grand piano', '3')
        self.ableton.playClip('wavetable', '3')
        self.timeline.cue(
            action=self.filterSweepMaster(1.0, self.filterMax, self.filterMin))
        self.timeline.cueInSeconds(0.5,
                                   action=self.fadeLights(
                                       self.allLightsUsed, 0.5,
                                       self.lightNormal, self.lightMin))
        self.timeline.cueInSeconds(1.5,
                                   lambdaFunction=self.flickerLight(
                                       self.sideRight[1], 0.3,
                                       self.lightBoard.lightMin,
                                       self.lightBoard.lightMax))
        self.timeline.cueInSeconds(4.0,
                                   action=self.fadeLights(
                                       self.allLightsUsed, 2,
                                       self.lightBoard.lightMin,
                                       self.lightBoard.lightMax))
        self.timeline.cueInSeconds(4.0,
                                   action=self.filterSweepMaster(
                                       2.0, self.filterMin, self.filterMax))

    def executeTransition2(self):
        self.ableton.playClip('grand piano', '4')
        self.ableton.playClip('wavetable', '4')
        self.timeline.cue(
            action=self.filterSweepMaster(1.0, self.filterMax, self.filterMin))
        self.timeline.cueInSeconds(0.5,
                                   action=self.fadeLights(
                                       self.allLightsUsed, 0.5,
                                       self.lightNormal, self.lightMin))
        self.timeline.cueInSeconds(1.5,
                                   lambdaFunction=self.flickerLight(
                                       self.sideRight[1], 0.3,
                                       self.lightBoard.lightMin,
                                       self.lightBoard.lightMax))
        self.timeline.cueInSeconds(4.0,
                                   action=self.fadeLights(
                                       self.allLightsUsed, 2,
                                       self.lightBoard.lightMin,
                                       self.lightBoard.lightMax))
        self.timeline.cueInSeconds(4.0,
                                   action=self.filterSweepMaster(
                                       2.0, self.filterMin, self.filterMax))

    def executeTransition3(self):
        self.ableton.playClip('grand piano', '5')
        self.ableton.playClip('wavetable', '5')
        self.timeline.cue(
            action=self.filterSweepMaster(1.0, self.filterMax, self.filterMin))
        self.timeline.cueInSeconds(0.5,
                                   action=self.fadeLights(
                                       self.allLightsUsed, 0.5,
                                       self.lightNormal, self.lightMin))
        self.timeline.cueInSeconds(
            1.5,
            lambdaFunction=lambda: self.flickerLight(self.sideRight[
                1], 0.3, self.lightBoard.lightMin, self.lightBoard.lightMax))
        self.timeline.cueInSeconds(4.0,
                                   action=self.fadeLights(
                                       self.allLightsUsed, 2,
                                       self.lightBoard.lightMin,
                                       self.lightBoard.lightMax))
        self.timeline.cueInSeconds(4.0,
                                   action=self.filterSweepMaster(
                                       2.0, self.filterMin, self.filterMax))
        self.timeline.cueInSeconds(
            6,
            action=self.fadeLights(self.allLightsUsedExceptChannelTwo, 42,
                                   self.lightNormal, self.lightBoard.lightMin))
        self.timeline.cueInSeconds(
            48,
            action=self.fadeLights([2], 12, self.lightNormal,
                                   self.lightBoard.lightMin))
        self.timeline.cueInSeconds(48,
                                   action=self.filterSweepMaster(
                                       8, self.filterMax, 0))

    def executeTransition4(self):
        def outro():
            self.ableton.stop()
            self.timeline.clearScheduledActions()
            self.timeline.cueInSeconds(4.0,
                                       action=self.fadeLights(
                                           self.houseLights, 2.0,
                                           self.lightBoard.lightMin,
                                           self.lightNormal))

        self.timeline.cueInSeconds(6, lambdaFunction=outro())

    def flickerLight(self, channel: int, durationSeconds: float, lightMin: int,
                     lightMax: int):
        self.lightBoard.setChannel(channel, lightMax)
        self.timeline.cueInSeconds(durationSeconds,
                                   lambdaFunction=lambda: self.lightBoard.
                                   setChannel(channel, lightMin))

    def filterSweepMaster(self, durationSeconds: float, startValue: float,
                          endValue: float):
        frequency = self.ableton.getTrack('Master').get_device(
            'Auto Filter').get_parameter_by_name('Frequency')

        def updateFunction(value):
            frequency.value = value

        return LerpAction(durationSeconds, updateFunction, startValue,
                          endValue)

    def fadeParameter(self, parameter: live.Parameter, durationSeconds: float,
                      startLevel: float, endLevel: float):
        def updateFunction(value):
            parameter.value = value

        return LerpAction(durationSeconds, updateFunction, startLevel,
                          endLevel)

    def fadeVolume(self, track: live.Track, durationSeconds: float,
                   startLevel: float, endLevel: float):
        def updateFunction(value):
            track.volume = value

        return LerpAction(durationSeconds, updateFunction, startLevel,
                          endLevel)

    def fadeLights(self, channels, durationSeconds, startLevel, endLevel):
        def updateFunction(value):
            for channel in channels:
                self.lightBoard.setChannel(channel, int(value))

        return LerpAction(durationSeconds, updateFunction, startLevel,
                          endLevel)

    def fadeAllLights(self, durationSeconds, startLevel, endLevel):
        def updateFunction(value):
            for channel in range(self.lightBoard.channelMin,
                                 self.lightBoard.channelMax + 1):
                self.lightBoard.setChannel(channel, int(value))

        return LerpAction(durationSeconds, updateFunction, startLevel,
                          endLevel)

    def cleanup(self):
        del self.ableton