Esempio n. 1
0
    def end_device_audio_record(self, end_ts):
        device_id_list = list(self.device_audio_record.keys())
        jobs = {}
        job_index = 0

        for device_id in device_id_list:
            device_info = self.device_audio_record[device_id]

            last_action = device_info.get("action")
            last_update_ts = device_info.get("update_ts")
            last_start_type = device_info.get("start_type")
            last_start_ts = device_info.get("start_ts")
            last_phid = device_info.get("phid")
            last_live = device_info.get("live")
            last_pid = device_info.get("pid")
            last_tid = device_info.get("tid")
            last_album_id = device_info.get("album_id")
            last_netstat = device_info.get("netstat")
            last_controller = device_info.get("controller")
            last_start_pos = device_info.get("start_pos")
            last_end_pos = device_info.get("end_pos")
            last_audio_id = device_info.get("audio_id")
            last_key_id = device_info.get("key_id")
            last_user_id = device_info.get("user_id")

            diff_ts = int((end_ts - last_update_ts).total_seconds())

            if diff_ts >= 40:
                last_end_ts = last_update_ts + timedelta(seconds=30)
            else:
                last_end_ts = end_ts

            if last_end_ts is not None and last_end_ts < last_start_ts:
                last_end_ts = last_start_ts + timedelta(seconds=30)

            last_end_type = "stop"
            jobs[job_index] = [
                last_start_type, last_end_type,
                convert_into_utc_time(last_end_ts) if last_end_ts is not None
                else None, last_live, last_pid, last_tid, last_netstat,
                last_start_pos, last_end_pos, last_album_id, last_controller,
                last_audio_id, last_key_id, last_user_id,
                convert_into_utc_time(
                    last_start_ts.replace(second=0, minute=0,
                                          hour=0)), device_id,
                convert_into_utc_time(last_start_ts), last_phid
            ]
            job_index += 1

            del self.device_audio_record[device_id]

        if len(jobs) > 0:
            self.cassandra_connector.do_futures("update_device_audio_data",
                                                jobs)
Esempio n. 2
0
    def run(self, calculate_logs):
        self.init_cassandra()

        result = self.calculate_audio_logs(calculate_logs)

        jobs = {}
        job_index = 0

        if result is not None:
            for device_id in result:
                for phid in result[device_id]:
                    for start_time in result[device_id][phid]:
                        end_type = result[device_id][phid][start_time][
                            "end_type"]
                        end_time = result[device_id][phid][start_time][
                            "end_time"]
                        start_type = result[device_id][phid][start_time][
                            "start_type"]
                        live_status = result[device_id][phid][start_time][
                            "live_status"]
                        pid = result[device_id][phid][start_time]["pid"]
                        tid = result[device_id][phid][start_time]["tid"]
                        netstat = None

                        if end_time is not None and end_time < start_time:
                            end_time = start_time + timedelta(seconds=30)

                        jobs[job_index] = [
                            start_type, end_type,
                            convert_into_utc_time(end_time)
                            if end_time is not None else None, live_status,
                            pid, tid, netstat,
                            convert_into_utc_time(
                                start_time.replace(second=0, minute=0,
                                                   hour=0)), device_id,
                            convert_into_utc_time(start_time), phid
                        ]
                        job_index += 1

        if len(jobs) > 0:
            try:
                self.cassandra_connector.do_futures("update_device_audio_data",
                                                    jobs)
            except:
                error_data = traceback.format_exc()
                logging.error(
                    "update device audio data error: {0}".format(error_data))
    def run(self, calculate_logs):
        self.init_cassandra()

        self.action_adjust_list = [("stop", "start"), ("complete", "start"),
                                   ("start", "play"), ("play", "complete"),
                                   ("play", "stop"), ("play", "pause"),
                                   ("resume", "play"), ("pause", "resume"),
                                   ("seek_start", "start")]

        result = self.calculate_audio_logs(calculate_logs)

        jobs = {}
        job_index = 0

        if result is not None:
            for device_id in result:
                for phid in result[device_id]:
                    for start_time in result[device_id][phid]:
                        end_type = result[device_id][phid][start_time][
                            "end_type"]
                        end_time = result[device_id][phid][start_time][
                            "end_time"]
                        start_type = result[device_id][phid][start_time][
                            "start_type"]
                        live_status = result[device_id][phid][start_time][
                            "live_status"]
                        pid = result[device_id][phid][start_time]["pid"]
                        tid = result[device_id][phid][start_time]["tid"]
                        album_id = result[device_id][phid][start_time][
                            "album_id"]
                        netstat = result[device_id][phid][start_time][
                            "netstat"]
                        controller = result[device_id][phid][start_time][
                            "controller"]
                        start_pos = result[device_id][phid][start_time][
                            "start_pos"]
                        end_pos = result[device_id][phid][start_time][
                            "end_pos"]
                        audio_id = result[device_id][phid][start_time][
                            "audio_id"]
                        key_id = result[device_id][phid][start_time]["key_id"]
                        user_id = result[device_id][phid][start_time][
                            "user_id"]

                        if end_time is not None and end_time < start_time:
                            end_time = start_time + timedelta(seconds=30)

                        jobs[job_index] = [
                            start_type, end_type,
                            convert_into_utc_time(end_time)
                            if end_time is not None else None, live_status,
                            pid, tid, netstat, start_pos, end_pos, album_id,
                            controller, audio_id, key_id, user_id,
                            convert_into_utc_time(
                                start_time.replace(second=0, minute=0,
                                                   hour=0)), device_id,
                            convert_into_utc_time(start_time), phid
                        ]
                        job_index += 1

        if len(jobs) > 0:
            try:
                self.cassandra_connector.do_futures("update_device_audio_data",
                                                    jobs)
            except:
                error_data = traceback.format_exc()
                logging.error(
                    "update device audio data error: {0}".format(error_data))