Beispiel #1
0
def facts(context, member):
    date_fields = ['date_from', 'date_up_to', 'date_of_receiving']
    args = {}
    if member.contract_address:
        oracle = OracleHandler()
        fact_keys = oracle.facts_keys(member.contract_address)
        facts_dict = []
        for item in fact_keys:
            fact = oracle.fact(member.contract_address, item)
            f = json.loads(fact[2])
            for date_item in date_fields:
                if date_item in f:
                    f[date_item] = date_converter.string_to_date(
                        f[date_item], current_format='%Y-%m-%dT%H:%M:%S')

            facts_dict.append({
                'id':
                item,
                'from':
                fact[0],
                'date':
                datetime.datetime.fromtimestamp(int(fact[1])),
                'fact':
                f
            })
        args['facts'] = facts_dict
        args['member'] = member
        context.update(args)
    return context
Beispiel #2
0
def convert_from_string(string, current_format, to_format, to_type=str):
    if to_type == str:
        return converter.string_to_string(string, current_format, to_format)
    elif to_type == datetime:
        return converter.string_to_datetime(string, current_format, to_format)
    elif to_type == date:
        return converter.string_to_date(string, current_format)
    elif to_type == float:
        return converter.string_to_timestamp(string, current_format)
Beispiel #3
0
def convert_from_string(string, current_format, to_format, to_type=str):
    if to_type == str:
        return converter.string_to_string(string, current_format, to_format)
    elif to_type == datetime:
        return converter.string_to_datetime(string, current_format, to_format)
    elif to_type == date:
        return converter.string_to_date(string, current_format)
    elif to_type == float:
        return converter.string_to_timestamp(string, current_format)
Beispiel #4
0
    def wrapper(self, *args, **kwargs):
        start = request.args.get('start')
        end = request.args.get('end')

        if not start or not end:
            return jsonify(code=400, message='请求的时间区间不正确'), 400

        start_obj = date_converter.string_to_date(start, timestamp_format)
        end_obj = date_converter.string_to_date(end, timestamp_format)

        # 超过了当天时间
        events = []
        if start_obj > date.today():
            return jsonify(events)

        if end_obj < date.today() or (date.today().day == 1 and start_obj.month != date.today().month):
            # 区间[start, end), end通常为下个月的1号
            total_day = (end_obj - start_obj).days
        else:
            # 需要含当天
            total_day = (date.today() - start_obj).days + 1

        for idx in range(total_day):
            str_fmt = start_obj.replace(
                day=start_obj.day + idx).strftime(timestamp_format)
            timestamp = date_converter.string_to_timestamp(
                str_fmt, timestamp_format)
            ret = f(self, str_fmt, timestamp)
            if ret is None:
                continue

            url, title, className = ret

            events.append(
                dict(title=title, start=str_fmt, url=url, className=className))

        return jsonify(events)
Beispiel #5
0
 def get_all_data_by_day(cls, day_format):
     the_date = date_converter.string_to_date(day_format, '%Y-%m-%d')
     return cls.query.filter(cls.flightDate == the_date).all()
Beispiel #6
0
 def has_related_status_by_day(cls, day_format, status=InitialState):
     "获取指定日期是否存在对应状态的数据"
     the_date = date_converter.string_to_date(day_format, '%Y-%m-%d')
     e = exists().where(cls.flightDate == the_date).where(
         cls.status == status)
     return cls.query.filter(e).count() != 0
Beispiel #7
0
    def save_log(self, date_str):
        try:
            all_data = request.get_json()
            if all_data is None or 'datas' not in all_data:
                return (400, '请求的数据没有使用正确的格式。', {})

            all_data = all_data['datas'] or []
            if not len(all_data):
                return (400, '为什么要存储空的数据内容呢?', {})

            # TODO: 简单点,把之前的数据全部清掉
            exists = FlightLog.get_all_data_by_day(date_str)
            for item in exists:
                if item.status == Finished:
                    return (400, '当天的日志已经提交了,你可能提交的是旧数据?', {})
                self.session.delete(item)

            mission_data = self.saved_fly_type_check(all_data)
            for index, data in enumerate(all_data):
                # WUJG: 对数据的格式进行转换,以便允许生成下面的实例
                computed_data = {}
                # TODO: 徐州的机务应为停电问题导致暂存不进行必填验证
                # 但暂存验证应该是能更加确保数据准确性
                # 到底如何进行验证值得思考
                # if data[0] is None or data[0] == '':
                #     return (400, '请选择任务类型', {})
                # if data[6] is None or data[6] == '':
                #     return (400, '请输入正确的滑出时间', {})
                # if data[7] is None or data[7] == '':
                #     return (400, '请输入正确的起飞时间', {})
                # if data[8] is None or data[8] == '':
                #     return (400, '请输入正确的降落时间', {})
                # if data[9] is None or data[9] == '':
                #     return (400, '请输入正确的停止时间', {})
                for idx, cl_cfg in enumerate(columns):
                    data[idx] = data[idx] if data[idx] else ''
                    computed_data[cl_cfg['data']] = data[idx]
                    if cl_cfg['data'] == 'engineTime' and \
                            self.time_check(data[idx]) and \
                            self.relate_engineTimeCheck(computed_data):
                        arn = computed_data.get('aircraftId')
                        if arn in mission_data:
                            if mission_data[arn]:
                                computed_data['EngineTimeExtra'] = '00:06'
                            else:
                                computed_data['EngineTimeExtra'] = '00:02'
                            mission_data.pop(arn)

                form = self._create_form_class.from_json(computed_data)
                model = self.model()
                form.populate_obj(model)

                # 由于日志编号在API端计算的时候必须提供,下面使用自动生成的算法
                model.flightlogId = ''.join(['FXRZBH', date_str,
                                             '%02d' % (index + 1,)])
                model.flightDate = date_converter.string_to_date(
                    date_str, self._timestamp_format)

                # TODO: 能做到新建的新建、更新的更新吗?
                # WUJG: 为了简化,目前这里全部标识为新建
                self._custom_action(model, dict(), action='create',
                                    direct_commit=False)

                self.session.add(model)
            self.session.commit()
        except Exception as ex:
            self.session.rollback()
            return (400, ex, {})

        return (200, 'ok', {'username': current_user.realName,
                            'timestamp': date.today().strftime('%Y-%m-%d')})
Beispiel #8
0
    try:
        yahoo_financials = YahooFinancials(company)
        price_history = yahoo_financials.get_historical_price_data(start_str, now_str, 'monthly')
        price_history_list = price_history[company]["prices"]
        price_len = len(price_history_list)
        
        tickers_index = tickers.index[tickers["Ticker"] == company]
#        fiscal_month = tickers.iloc[tickers_index].loc["Month of Foscal Yr End"]
        fiscal_month = tickers.iloc[tickers_index]["Month of Fiscal Yr End"].iloc[0]
        
        adj_price_row = []
        price_row = []
        
        for data_year in range (2008, now.year+1):
            for i in range (0, price_len):
                price_date = date_converter.string_to_date(price_history_list[i]['formatted_date'], '%Y-%m-%d')
                price_year = price_date.year
                if price_year > data_year:
                    adj_price_row = adj_price_row + [""]
                    price_row = price_row + [""]
                    break
                elif price_year == data_year:
                    price_month = price_date.month
                    if price_month > fiscal_month:
                        adj_price_row = adj_price_row + [""]
                        price_row = price_row + [""]
                        break
                    elif price_month == fiscal_month:
                        adj_price_row = adj_price_row + [price_history_list[i]['adjclose']]
                        price_row = price_row + [price_history_list[i]['close']]
                        break