Debian not taking daylight saving time into account in R - r

I use following code to find whether daylight saving is in use in Central Europe in day given by variables year, month and day.
timeString = paste(toString(year), formatC(month, width = 2, flag="0"), formatC(day, width = 2, flag="0"), "12", sep = "-")
time = strptime(timeString, format = "%Y-%m-%d-%H")
diff = as.numeric(as.POSIXct(time, tz="UTC") - as.POSIXct(time, tz="Europe/Prague"))
On my PC (Ubuntu 16.04), diff is 2 when daylight saving is active, 1 othervise, but on server with Debian 8.8 it is 1 in all cases. Do you know how to set-up the server to behave as Ubuntu? Thanks.
Update: The change of Debian time settings would also change time used for crontab, which is undesirable. Reinstaling R with new configuration seemed risky becase there runs a few R script operationally every few minutes. So i chose "ugly" solution in form of R function:
DaylightSaving = function(year, month, day) {
# years 2010-2030
if (year < 2010 || year > 2030) {
stop("The function is implemented now only for years 2010-2030")
}
dayStart = c(28, 27, 25, 31, 30, 29, 27, 26, 25, 31, 29, 28, 27, 26,
31, 30, 29, 28, 26, 25, 31)
dayEnd = c(31, 30, 28, 27, 26, 25, 30, 29, 28, 27, 25, 31, 30, 29,
27, 26, 25, 31, 29, 28, 27)
if (month < 3 || month > 10) {
return(FALSE)
} else if (month == 3 && day < dayStart[year - 2009]) {
return(FALSE)
} else if (month == 10 && day >= dayEnd[year - 2009]) {
return(FALSE)
}
return(TRUE)
}

First of all, if you want to check whether daylight saving is in use, you can simply do:
#Make a test date
atime <- as.POSIXct("2017-05-23 13:25",
tz = "Europe/Prague")
#test for DST
as.POSIXlt(atime)$isdst > 0
The POSIXlt class is internally a list with an element isdst that is 0 if daylight saving time is not active, positive when it is, and negative when that information is not available. (see ?DateTimeClasses).
I would also like to point out the following from the help pages on timezones :
Note that except where replaced, the operation of time zones is an OS
service, and even where replaced a third-party database is used and
can be updated (see the section on ‘Time zone names’). Incorrect
results will never be an R issue, so please ensure that you have the
courtesy not to blame R for them.
The problem isn't R, but your Debian installation disregarding daylight saving time. You can solve this by configuring R with the option --with-internal-tzcode, so it uses its own timezone database. But this is generally not necessary if your Debian's timezone system is set up correctly. More info on how to configure R can be found on the help page ?timezones and in the Installation and Administration manual - appendix B.
The best way to solve this, is to make sure that your Debian installation deals with daylight saving time correctly. You can start with checking whether you have a correct version of the tzdata package.
There's a similar question on unix.stackexchange.com :
https://unix.stackexchange.com/questions/274878/system-disregards-daylight-saving-time

Related

Airflow failed to get task instance

i have tried to run a simple task using airflow bash operator but keep getting stuck on my DAG never stop running, it stays like green forever without success or fail, when i check the logs i see something like this. Thanks in advance for your time and answers
**`your text`**airflow-scheduler_1 | [SQL: INSERT INTO task_fail (task_id, dag_id, execution_date, start_date, end_date, duration) VALUES (%(task_id)s, %(dag_id)s, %(execution_date)s, %(start_date)s, %(end_date)s, %(duration)s) RETURNING task_fail.id]
airflow-scheduler_1 | [parameters: {'task_id': 'first_task', 'dag_id': 'LocalInjestionDag', 'execution_date': datetime.datetime(2023, 1, 20, 8, 0, tzinfo=Timezone('UTC')), 'start_date': datetime.datetime(2023, 1, 23, 3, 35, 27, 332954, tzinfo=Timezone('UTC')), 'end_date': datetime.datetime(2023, 1, 23, 3, 35, 27, 710572, tzinfo=Timezone('UTC')), 'duration': 0}]
postgres_1 | 2023-01-23 03:55:59.712 UTC [4336] ERROR: column "execution_date" of relation "task_fail" does not exist at character 41"""
I have tried with execution_datetime , using xcom_push and creating functions with xcom and changing to python operator but everything still fall back to same error

DateTime Series Issue PineScript

I'm working to fill an array with High/Low pivot points of the "Previous Trading Day", but I'm facing an issue in terms of the time series (second section below!). I'm not sure if that PineScript's bug or my misunderstanding of how are the time-series functions working!! Please Help, very organize details.
Calling for current Trading Day, then selected the regular session ( No issues in this part )
//------------------ Selected Day of Trading
//Start Day
Start_Period= timestamp(syminfo.timezone, 2020, 12, 09, 00, 00, 00)
//End Day
End_Period = timestamp(syminfo.timezone, 2020, 12, 09, 23, 59, 59)
//------------------ Filtring Session
// Regular Session
t_reg = time("1440", session.regular)
The issue only in this coding box.
Pine script would not recognize the result of Change_Time
// Detect the change of time between selected day trading and most recent day trading (t-t[1])
Change_Time = security(syminfo.tickerid, "1440", change(time))
FunYesterday()=>
if time >= Start_Period-Change_Time and time <= End_Period-Change_Time and t_reg
[pivothigh(close, 3, 2), pivotlow(close, 3, 2)]
However, if I substitute the security function of Change_time= 60*60*24*1000will work fine!!, but I tried to avoid this method because of time deference on weekends, and other holidays.
Final Section find Pivot and Create Array ( No issues in this part )
//------------------ Pivot point at 15 min.
[ph2, pl2] = security(syminfo.tickerid, "15", FunYesterday(), lookahead = barmerge.lookahead_off)
ph2_filter= ph2 == ph2[1]?na:ph2
pl2_filter= pl2 == pl2[1]?na:pl2
//------------------ Array Part
var a = array.new_float()
if (not na(ph2_filter))
array.push(a,ph2_filter)
else if (not na(pl2_filter))
array.push(a,pl2_filter)
if barstate.islast and array.size(a)>0
y=label.new(bar_index, close, "Initial\na: " + tostring(a))
label.delete(y[1])
I'm very open if you have any other idea to import data from the most recent trading day only!!. Thank you

Finstr get_xbrl_statement error parsing Extracted XBRL Instance Document

Most recent AAPL 10-k XBRL Instance Document for example:
doc <- "https://www.sec.gov/Archives/edgar/data/320193/000032019319000119/0000320193-19-000119-index.htm"
Run xbrlDoAll and xbrl_get_statements from XBRL and finstr packages, respectively
get_xbrl_doc <- xbrlDoAll(doc)
statements <- xbrl_get_statements(get_xbrl_doc)
Error: Each row of output must be identified by a unique combination of keys.
Keys are shared for 34 rows:
* 6, 8
* 5, 7, 9
* 49, 51
* 48, 50
* 55, 57
* 54, 56
* 11, 13
* 10, 12
* 25, 27
* 24, 26
* 59, 61
* 58, 60
* 29, 31
* 28, 30
* 63, 64, 66
* 62, 65
This sequence works perfectly up until 2019 when Apple switched to "Extracted XBRL Instance Document" from "XBRL Instance Document". Has anybody found a work around?
Not only have they switched that, but now the fact ID brings some kind of 32-digit key that seems to have no connections with any of the other files in the taxonomy. This is probably related to the iXBRL process and I've seen it with another company as well.
However, if the problem is just the word "Extracted", then you just need to change the script, but I'm guessing this is not the case and the solution relates to finding out what those 32-digit keys mean.
I'm not an R user and I don't use Finstr, but I guess we have the same problem. So, the answer to your question would be: you need to write your own parser now or wait until someone finishes theirs.

Datetime and Pytz Timezone .weekday() issue

I'm running into an issue when I'm trying to create a histogram of specific createdAt datetimes for orders. The issue is that even after created timezone aware datetimes, the .weekday() shows up as the same day, even though it should be a different time
The code I'm using to test this occurrence is as follows:
import datetime
import pytz
value = {
'createdAt': '2017-04-24T00:48:03+00:00'
}
created_at = datetime.datetime.strptime(value['createdAt'], '%Y-%m-%dT%H:%M:%S+00:00')
timezone = pytz.timezone('America/Los_Angeles')
created_at_naive = created_at
created_at_aware = timezone.localize(created_at_naive)
print(created_at_naive) # 2017-04-24 00:48:03
print(created_at_aware) # 2017-04-24 00:48:03-07:00
print(created_at_naive.weekday()) # 0 (Monday)
print(created_at_aware.weekday()) # 0 (should be Sunday)
The problem is that you need to actually change the datetime to the new timezone:
>>> timezone('UTC').localize(created_at)
datetime.datetime(2017, 4, 24, 0, 48, 3, tzinfo=<UTC>)
>>>timezone('UTC').localize(created_at).astimezone(timezone('America/Los_Angeles'))
datetime.datetime(2017, 4, 23, 17, 48, 3, tzinfo=<DstTzInfo 'America/Los_Angeles' PDT-1 day, 17:00:00 DST>)

SQLite CGI Programming (SQLITE_CANTOPEN)

When I am trying to use sqlite3_exec to insert new data into the database, it returns error 14 (SQLITE_CANTOPEN). But when I am using sqlite3_prepare_v2 to select, it works fine. Is there an issue with permissions? How to fix it?
sprintf(temp, "INSERT INTO owned (pid, oname, okey, ohp, oatt, odef) VALUES (%d, %c%s%c, %c%s%c, %d, %d, %d);", pid, 34, poname, 34, 34, passkey, 34, sqlite3_column_int(res3,0), sqlite3_column_int(res3,1), sqlite3_column_int(res3,2));
error = sqlite3_exec(conn, temp, 0, 0, 0);

Resources