How to use the arrow.Arrow function in arrow

To help you get started, we’ve selected a few arrow examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github freqtrade / freqtrade / tests / optimize / test_backtesting.py View on Github external
'freqtrade.optimize.backtesting.file_dump_json',
        new=lambda n, r: (names.append(n), records.append(r))
    )

    backtesting = Backtesting(default_conf)
    results = pd.DataFrame({"pair": ["UNITTEST/BTC", "UNITTEST/BTC",
                                     "UNITTEST/BTC", "UNITTEST/BTC"],
                            "profit_percent": [0.003312, 0.010801, 0.013803, 0.002780],
                            "profit_abs": [0.000003, 0.000011, 0.000014, 0.000003],
                            "open_time": [Arrow(2017, 11, 14, 19, 32, 00).datetime,
                                          Arrow(2017, 11, 14, 21, 36, 00).datetime,
                                          Arrow(2017, 11, 14, 22, 12, 00).datetime,
                                          Arrow(2017, 11, 14, 22, 44, 00).datetime],
                            "close_time": [Arrow(2017, 11, 14, 21, 35, 00).datetime,
                                           Arrow(2017, 11, 14, 22, 10, 00).datetime,
                                           Arrow(2017, 11, 14, 22, 43, 00).datetime,
                                           Arrow(2017, 11, 14, 22, 58, 00).datetime],
                            "open_rate": [0.002543, 0.003003, 0.003089, 0.003214],
                            "close_rate": [0.002546, 0.003014, 0.003103, 0.003217],
                            "open_index": [1, 119, 153, 185],
                            "close_index": [118, 151, 184, 199],
                            "trade_duration": [123, 34, 31, 14],
                            "open_at_end": [False, False, False, True],
                            "sell_reason": [SellType.ROI, SellType.STOP_LOSS,
                                            SellType.ROI, SellType.FORCE_SELL]
                            })
    backtesting._store_backtest_result("backtest-result.json", results)
    assert len(results) == 4
    # Assert file_dump_json was only called once
    assert names == ['backtest-result.json']
    records = records[0]
    # Ensure records are of correct type
github aceisace / Inky-Calendar / inkycal / modules / inkycal_weather.py View on Github external
def calculate_forecast(days_from_today):
        """Get temperature range and most frequent icon code for forecast
        days_from_today should be int from 1-4: e.g. 2 -> 2 days from today
        """

        # Create a list containing time-objects for every 3rd hour of the day
        time_range = list(arrow.Arrow.range('hour',
                          now.shift(days=days_from_today).floor('day'),
                          now.shift(days=days_from_today).ceil('day')
                          ))[::3]

        # Get forecasts for each time-object
        forecasts = [forecast.get_weather_at(_.datetime) for _ in time_range]


        # Get all temperatures for this day
        daily_temp = [round(_.get_temperature(unit=temp_unit)['temp'],
                            ndigits=dec_temp) for _ in forecasts]
        # Calculate min. and max. temp for this day
        temp_range = '{}°/{}°'.format(max(daily_temp), min(daily_temp))


        # Get all weather icon codes for this day
github 17zuoye / luiti / luiti / daemon / ptm / params.py View on Github external
def generate_query_params(self):
        """
        provide config to visualSearch.js
        """
        # date range related.
        yesterday_str = self.yesterday().format("YYYY-MM-DD")
        self.current_luiti_visualiser_env["date_end"] = self.current_luiti_visualiser_env.get("date_end", yesterday_str)

        date_begin = ArrowParameter.get(self.current_luiti_visualiser_env["date_begin"])
        date_end = ArrowParameter.get(self.current_luiti_visualiser_env["date_end"])
        accepted_date_values = sorted(map(str, arrow.Arrow.range("day", date_begin, date_end)))

        # result
        query_params = {
            "accepted": {
                "date_value": accepted_date_values,
                "task_cls": self.task_class_names,
                "luiti_package": self.task_package_names,
            }
        }

        return query_params
github edavis / river / river / feed.py View on Github external
def next_check(self):
        """
        Return when this feed is due for a check.

        Returns a date far in the past (1/1/1970) if this feed hasn't
        been checked before. This ensures all feeds are checked upon
        startup.
        """
        if self.last_checked is None:
            return arrow.Arrow(1970, 1, 1)
        return self.last_checked + self.update_interval()
github meraki-analytics / cassiopeia / cassiopeia / core / common.py View on Github external
def default(self, obj):
        if isinstance(obj, Enum):
            return obj.name
        elif isinstance(obj, (datetime.datetime, arrow.Arrow)):
            return obj.isoformat()
        elif isinstance(obj, datetime.timedelta):
            return obj.seconds
        return json.JSONEncoder.default(self, obj)
github Weasyl / weasyl / weasyl / login.py View on Github external
def create(form):
    # Normalize form data
    username = clean_display_name(form.username)
    sysname = d.get_sysname(username)

    email = emailer.normalize_address(form.email)
    emailcheck = emailer.normalize_address(form.emailcheck)

    password = form.password
    passcheck = form.passcheck
    if form.day and form.month and form.year:
        try:
            birthday = arrow.Arrow(int(form.year), int(form.month), int(form.day))
        except ValueError:
            raise WeasylError("birthdayInvalid")
    else:
        birthday = None

    # Check mismatched form data
    if password != passcheck:
        raise WeasylError("passwordMismatch")
    if email != emailcheck:
        raise WeasylError("emailMismatch")

    # Check invalid form data
    if birthday is None or d.age_in_years(birthday) < 13:
        raise WeasylError("birthdayInvalid")
    if not password_secure(password):
        raise WeasylError("passwordInsecure")
github csirtgadgets / csirtg-indicator-py-v1 / csirtg_indicator / utils / ztime.py View on Github external
def parse_timestamp(ts):
    if isinstance(ts, arrow.Arrow):
        return ts

    t = human_to_dt(ts)
    if t:
        return t

    ts_len = len(ts)
    
    try:
        t = arrow.get(ts)
        if t.year < 1980:
            if type(ts) == datetime:
                ts = str(ts)
            if ts_len == 8:
                ts = '{}T00:00:00Z'.format(ts)
                t = arrow.get(ts, 'YYYYMMDDTHH:mm:ssZ')
github ovh / depc / depc / utils / redis_cache.py View on Github external
def get_period_seconds(cls, period):
        if not period:
            return None

        if isinstance(period, int):
            period_seconds = period
        elif isinstance(period, str):
            match = cls.DURATION_REGEX.match(period)
            assert match, "Invalid period"

            until = arrow.Arrow(**match.groupdict())
            period_seconds = (until - arrow.utcnow()).seconds
        elif callable(period):
            period_seconds = int(period())
        else:
            raise Exception("Period must be a string, int or callable")

        assert period_seconds > 0, "Period must be more than 1s"
        return period_seconds