Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_caltrack_sufficiency_criteria_fail_no_gap_and_not_enough_days():
data_quality = pd.DataFrame(
{
"meter_value": [1, 1],
"temperature_not_null": [1, 5],
"temperature_null": [0, 5],
"start": pd.date_range(start="2016-01-02", periods=2, freq="D", tz="UTC"),
}
).set_index("start")
requested_start = pd.Timestamp("2016-01-02").tz_localize("UTC")
requested_end = pd.Timestamp("2016-01-04").tz_localize("UTC")
data_sufficiency = caltrack_sufficiency_criteria(
data_quality,
requested_start,
requested_end,
num_days=3,
min_fraction_daily_coverage=0.9,
min_fraction_hourly_temperature_coverage_per_period=0.9,
)
assert data_sufficiency.status == "FAIL"
assert data_sufficiency.criteria_name == ("caltrack_sufficiency_criteria")
assert len(data_sufficiency.warnings) == 4
warning0 = data_sufficiency.warnings[0]
assert warning0.qualified_name == (
"eemeter.caltrack_sufficiency_criteria.incorrect_number_of_total_days"
# 归属于少数股东的综合收益总额
attributableToMinorityShareholders = lines[30].split()[1:-1]
result_list = []
for idx, _ in enumerate(reportDate):
if start_date:
if pd.Timestamp(reportDate[idx]) < pd.Timestamp(start_date):
continue
if report_period and not is_same_date(report_period, reportDate[idx]):
continue
reportEventDate = get_report_event_date(security_item, report_period=reportDate[idx])
# use report_event_date to filter the reportEventDate before it for not getting future data
if report_event_date and pd.Timestamp(report_event_date) < pd.Timestamp(reportEventDate):
continue
the_json = {
"id": '{}_{}'.format(security_item["id"], reportDate[idx]),
"reportPeriod": to_time_str(reportDate[idx]),
"timestamp": to_time_str(reportEventDate),
"reportEventDate": to_time_str(reportEventDate),
"securityId": security_item["id"],
"code": security_item["code"],
# /*营业总收入*/
# 营业收入
"operatingRevenue": to_float(operatingRevenue[idx]),
# /*营业总成本*/
"operatingTotalCosts": to_float(operatingTotalCosts[idx]),
# 营业成本
"operatingCosts": to_float(operatingCosts[idx]),
# http://www.tradingtheodds.com/nyse-full-day-closings/
USMemorialDay1964to1969 = Holiday(
'Memorial Day',
month=5,
day=30,
start_date=Timestamp('1964-01-01'),
end_date=Timestamp('1969-12-31'),
observance=nearest_workday,
)
USMemorialDay = Holiday(
# NOTE: The definition for Memorial Day is incorrect as of pandas 0.16.0.
# See https://github.com/pydata/pandas/issues/9760.
'Memorial Day',
month=5,
day=25,
start_date=Timestamp('1971-01-01'),
offset=DateOffset(weekday=MO(1)),
)
# http://www.tradingtheodds.com/nyse-full-day-closings/
USIndependenceDayBefore1954 = Holiday(
'July 4th',
month=7,
day=4,
end_date=Timestamp('1953-12-31'),
observance=sunday_to_monday,
)
USIndependenceDay = Holiday(
'July 4th',
month=7,
day=4,
start_date=Timestamp('1954-01-01'),
observance=nearest_workday,
Regularly-Observed Early Closes:
- Lunar New Year's Eve
- Christmas Eve
- New Year's Eve
Additional Irregularities:
- Closes frequently for severe weather.
"""
name = 'XHKG'
tz = timezone('Asia/Hong_Kong')
open_times = (
(None, time(10, 1)),
(pd.Timestamp('2011-03-07'), time(9, 31)),
)
close_times = (
(None, time(16)),
)
regular_early_close_times = (
(None, time(12, 30)),
(pd.Timestamp('2011-03-07'), time(12, 00)),
)
def __init__(self, *args, **kwargs):
super(XHKGExchangeCalendar, self).__init__(*args, **kwargs)
lunisolar_holidays = (
chinese_buddhas_birthday_dates,
chinese_lunar_new_year_dates,
day_after_mid_autumn_festival_dates,
def save(self, metric_key, trial_id, epoch, value):
"""
Save metrics to MetricManager
"""
metric_key = validate_identifier(metric_key, keyname='Metric name')
record = dict(Epoch=epoch, Value=value,
Timestamp=pd.Timestamp.now())
return self._save(metric_key=metric_key,
trial_id=trial_id, record=record)
"""
r = session or requests.session()
dt = datetime.strptime(feed_date, '%Y-%m-%d %H:%M:%S')
# Get all available files
dates_url = "https://files.hrote.hr/files/EKO_BG/FORECAST/SOLAR/FTP/TEST_DRIVE/dates.json"
response = r.get(dates_url)
dates = response.json()
# Use latest file to get more up to date estimation
solar_url = 'https://files.hrote.hr/files/EKO_BG/FORECAST/SOLAR/FTP/TEST_DRIVE/{0}'.format(dates[-1]["Filename"])
response = r.get(solar_url)
obj = response.json()
df = pd.DataFrame.from_dict(obj['FullPower']).set_index('Timestamp')
df.index = pd.to_datetime(df.index) # cast strings to datetimes
solar_production_dt = pd.Timestamp(feed_date, tz='Europe/Zagreb').floor('1h')
try:
solar = df['Value'].loc[solar_production_dt]
# Converting to MW
solar *= 0.001
except KeyError:
logger.warning("No value for Solar power production on {0}".format(solar_production_dt))
solar = None
return solar
1984: Timestamp('1984-04-04'),
1985: Timestamp('1985-04-05'),
1986: Timestamp('1986-04-05'),
1987: Timestamp('1987-04-05'),
1988: Timestamp('1988-04-04'),
1989: Timestamp('1989-04-05'),
1990: Timestamp('1990-04-05'),
1991: Timestamp('1991-04-05'),
1992: Timestamp('1992-04-04'),
1993: Timestamp('1993-04-05'),
1994: Timestamp('1994-04-05'),
1995: Timestamp('1995-04-05'),
1996: Timestamp('1996-04-04'),
1997: Timestamp('1997-04-05'),
1998: Timestamp('1998-04-05'),
1999: Timestamp('1999-04-05'),
2000: Timestamp('2000-04-04'),
2001: Timestamp('2001-04-05'),
2002: Timestamp('2002-04-05'),
2003: Timestamp('2003-04-05'),
2004: Timestamp('2004-04-04'),
2005: Timestamp('2005-04-05'),
2006: Timestamp('2006-04-05'),
2007: Timestamp('2007-04-05'),
2008: Timestamp('2008-04-04'),
2009: Timestamp('2009-04-04'),
2010: Timestamp('2010-04-05'),
2011: Timestamp('2011-04-05'),
2012: Timestamp('2012-04-04'),
2013: Timestamp('2013-04-04'),
2014: Timestamp('2014-04-05'),
2015: Timestamp('2015-04-05'),
observance=sunday_to_monday,
)
USWashingtonsBirthDayBefore1964 = Holiday(
'Washington''s Birthday',
month=2,
day=22,
start_date=Timestamp('1880-01-01'),
end_date=Timestamp('1963-12-31'),
observance=sunday_to_monday,
)
USWashingtonsBirthDay1964to1970 = Holiday(
'Washington''s Birthday',
month=2,
day=22,
start_date=Timestamp('1964-01-01'),
end_date=Timestamp('1970-12-31'),
observance=nearest_workday,
)
USPresidentsDay = Holiday('President''s Day',
start_date=Timestamp('1971-01-01'),
month=2, day=1,
offset=DateOffset(weekday=MO(3)))
# http://www.tradingtheodds.com/nyse-full-day-closings/
USThanksgivingDayBefore1939 = Holiday('Thanksgiving Before 1939',
start_date=Timestamp('1864-01-01'),
end_date=Timestamp('1938-12-31'),
month=11, day=30,
offset=DateOffset(weekday=TH(-1)))
# http://www.tradingtheodds.com/nyse-full-day-closings/
USThanksgivingDay1939to1941 = Holiday('Thanksgiving 1939 to 1941',
start_date=Timestamp('1939-01-01'),
end_date=Timestamp('1941-12-31'),
ts_tmin = self.oseries.series.index.min()
# Get tmin from the stressmodels
elif use_stresses:
ts_tmin = pd.Timestamp.max
for stressmodel in self.stressmodels.values():
if stressmodel.tmin < ts_tmin:
ts_tmin = stressmodel.tmin
# Get tmin and tmax from user provided values
else:
ts_tmin = pd.Timestamp(tmin)
# Set tmin properly
if tmin is not None and use_oseries:
tmin = max(pd.Timestamp(tmin), ts_tmin)
elif tmin is not None:
tmin = pd.Timestamp(tmin)
else:
tmin = ts_tmin
# adjust tmin and tmax so that the time-offset is equal to the stressmodels.
if freq is None:
freq = self.settings["freq"]
tmin = tmin.floor(freq) + self.settings["time_offset"]
# assert tmax > tmin, \
# self.logger.error('Error: Specified tmax not larger than '
# 'specified tmin')
# if use_oseries:
# assert self.oseries.series.loc[tmin: tmax].size > 0, \
# self.logger.error(
# 'Error: no observations between tmin and tmax')
def reference_time(self, val):
self._reference_time = pd.Timestamp(val, unit='s')