예제 #1
0
def convert_from_timestamp(timestamp, to_format, to_type=str):
    if to_type == str:
        return converter.timestamp_to_string(timestamp, to_format)
    elif to_type == datetime:
        return converter.timestamp_to_datetime(timestamp, to_format)
    elif to_type == date:
        return converter.timestamp_to_date(timestamp)
예제 #2
0
def convert_from_timestamp(timestamp, to_format, to_type=str):
    if to_type == str:
        return converter.timestamp_to_string(timestamp, to_format)
    elif to_type == datetime:
        return converter.timestamp_to_datetime(timestamp, to_format)
    elif to_type == date:
        return converter.timestamp_to_date(timestamp)
예제 #3
0
    skipped = False

    time_rn = time.time()
    time_in_three_months = 2629743.83 * 3
    for row in table.findAll('tr'):
        if not skipped:
            skipped = True
            continue

        user_id = row.find('a', {'class': 'user-link'}).get('data-id')
        last_seen = row.find('a', {'data-tip': 'bottom'}).get('href')[33:]

        if time_rn - int(last_seen) < time_in_three_months:

            day = date_converter.timestamp_to_string(int(last_seen),
                                                     "%d/%m/%Y")
            last_seen = int(date_converter.string_to_timestamp(
                day, "%d/%m/%Y")) + 7200

            history[last_seen] = user_id

    properties['history'] = history
    data[original_id] = properties
    print ""

f = open(output, 'a')

for item in data:

    for history in data[item]['history']:
        begin_date = date_converter.timestamp_to_string(int(history), "%m/%d")
예제 #4
0
    def create_view(self):
        # 飞行器列表编辑页面的视图处理

        if not self.can_create and \
                not self.can_edit and \
                not self.can_view_details and \
                not self.can_finish:
            return abort(403)

        timestamp = request.args.get('timestamp', None)
        if timestamp is None:
            return abort(404)
        try:
            timestamp = float(timestamp)
        except ValueError:
            return abort(404)
        except TypeError:
            return abort(404)

        timestamp_obj = date_converter.timestamp_to_datetime(timestamp)
        if timestamp_obj > datetime.now():
            return abort(404)

        td = date_converter.timestamp_to_string(
            timestamp, self._timestamp_format)

        exist = FlightLog.get_all_data_by_day(td)
        datas = []
        # 与状态相关的内容
        creator, create_time, commiter, commit_time = None, None, None, None

        # 转为可JSON序列化的内容
        # 这段for 循环的逻辑实在是尴尬
        # 为啥要这么做
        for item in exist:
            if creator is None:
                creator = get_last_create_index(
                    item, InitialState, 'createUserName')
            if create_time is None:
                create_time = get_last_create_index(
                    item, InitialState, 'createTime')
                if create_time:
                    create_time = create_time.strftime('%Y-%m-%d')
            if commiter is None:
                commiter = get_last_create_index(
                    item, Finished, 'reviewUserName')
            if commit_time is None:
                commit_time = get_last_create_index(
                    item, Finished, 'reviewTime')
                if commit_time:
                    commit_time = commit_time.strftime('%Y-%m-%d')

            datas.append(item.to_json())

        # 获取可选择的飞机
        _columns = deepcopy(columns)
        # TODO: 注意,目前强制编码为y5b的飞机
        _columns[headers.index(_aircraftName)]['selectOptions'] = [
            aircraft.id for aircraft in get_allowed_aircrafts('y5b')]
        _columns[headers.index(_flyPropertyName)]['selectOptions'] = [
            item.name for item in FlyNature.query.all()]
        allowed_airports = [item.name for item in Airport.query.all()]
        _columns[headers.index(_takeOffAirportName)][
            'selectOptions'] = allowed_airports
        _columns[headers.index(_landAirportName)][
            'selectOptions'] = allowed_airports
        _columns[headers.index(_formulaName)]['selectOptions'] = [
            item.name for item in Formula.query.all()]
        # 获取允许的飞行员
        _columns[headers.index(_captain1)]['selectOptions'] = [
            item.name for item in Pilot.get_all()]
        _columns[headers.index(_captain2)]['selectOptions'] = [
            item.name for item in Pilot.get_all()]
        _columns[headers.index(_captain3)]['selectOptions'] = [
            item.name for item in Pilot.get_all()]

        is_readonly = FlightLog.has_related_status_by_day(td, Finished)

        contextMenu = {
            "items": {
                "row_above": {
                    "name": '向上新增一行',
                },
                "row_below": {
                    "name": '向下新增一行',
                },
                "remove_row": {
                    "name": '删除选中行',
                },
                "hsep1": "---------",
                "undo": {
                    "name": '撤销',
                },
                "redo": {
                    "name": '重做',
                }
            }
        }

        if not self.can_create:
            contextMenu['items'].pop('row_above')
            contextMenu['items'].pop('row_below')

        if not self.can_delete:
            contextMenu['items'].pop('remove_row')

        if is_readonly:
            contextMenu = None
            # 每一个内容都不允许编辑
            for item in _columns:
                item['readOnly'] = True
        return self.render(
            template=self.create_template,
            form=self.create_form(),
            headers=headers,
            columns=_columns,
            date_str=td,
            datas=datas,
            save_url=self.get_url('.save_log'),
            commit_url=self.get_url('.commit_log'),
            creator=creator,
            createTime=create_time,
            commiter=commiter,
            commitTime=commit_time,
            is_readonly=is_readonly,
            can_create=self.can_create,
            can_delete=self.can_delete,
            can_edit=self.can_edit,
            can_commit=self.can_finish,
            context_menu=contextMenu,
            time_columns=[
                # headers.index('开车时间'),
                headers.index('滑出时间'),
                headers.index('起飞时间'),
                headers.index('降落时间'),
                # headers.index('关车时间'),
                headers.index('停止时间'),
            ],
            calc_index={
                'typeProp': 'missionType',
                'typeIndex': headers.index('任务类型'),
                'startProp': 'skidoffTime',
                'startIndex': headers.index('滑出时间'),
                'endProp': 'stopTime',
                'endIndex': headers.index('停止时间'),
                'aircraftIdIndex': headers.index(_aircraftName),
                'aircraftIdProp': 'aircraftId',
                'flightTimeIndex': headers.index('飞行时间'),
                'engineTimeProp': 'engineTime',
                'engineTimeIndex': headers.index('发动机时间'),
            },
        )
예제 #5
0
def timestamp_to_datetimestamp(timestamp):
    if timestamp == 0 or timestamp == -1:
        return ''

    return date_converter.timestamp_to_string(timestamp, '%Y-%m-%d %H:%M:%S')