I wanted to get last six months of employee count by checking joining_date field
class Employee(models.Model):
employee_name = models.CharField(max_length=100)
joining_Date = models.DateField(blank=False, null=False)
Example:
July : 12,
June : 10,
May : 8,
April : 16,
March : 13,
February : 10,
I got an answer for that from 0svoid, check here
Its really working great! but problem is when there is no entry in particular month I want it to be 0 instead of not coming in the list.
Say for example june month not having any employee joining.
it should show like
July : 12,
June : 0,
May : 8,
April : 16,
March : 13,
February : 10,
instead of below one.
July : 12,
May : 8,
April : 16,
March : 13,
February : 10,
I want to work on many scenario(s) something like above , please suggest me any module or a way to generate reports to show in the template from the database(s)..
If you don't have information into your database, you can not count and show it.
Therefore you should create additional code:
from 'django.utils.dates import MONTHS
MONTHS_DICT = dict.fromkeys(MONTHS, 0)
# employees_per_month = answer from 0svoid
MONTHS_DICT.update(**employees_per_month)
print(MONTHS_DICT)
Today is 6th may.
The dag arguments are:
'start_date': datetime.datetime(2021, 5, 6),
'email_on_failure': False,
'email_on_retry': False,
'retries': 1,
'retry_delay': timedelta(minutes=5),
The schedule interval is:
schedule_interval="0 14 * * *"
It should have started at 2021-05-06 at 14 UTC.
But it has not been started.
This is expected.
start_date of 2021-05-06 and interval of 0 14 * * * means that the first run will start on 2021-05-07 14:00 this run will have execution_date of 2021-05-06 14:00
To understand why please read previous answer on this subject
I am reading a text file in R and want to replace every 3rd occurrence of '|' with '\n' here is my code and input data
**Input Data**
======================
'Monday, November 2, 2015|10:21:27|17:58:12|Tuesday, November 3, 2015|10:13:09|18:52:44|Wednesday, November 4, 2015|10:11:52|18:40:36|Thursday, November 5, 2015|10:31:42|18:16:57|Friday, November 6, 2015|10:13:13|--|Saturday, November 7, 2015|--|--|Sunday, November 8, 2015|--|--|Monday, November 9, 2015|--|--|Tuesday, November 10, 2015|10:03:20|18:07:52|Wednesday, November 11, 2015|09:40:20|18:42:20|Thursday, November 12, 2015|10:38:56|18:37:20|Friday, November 13, 2015|10:45:26|18:09:54|Saturday, November 14, 2015|--|--|Sunday, November 15, 2015|--|--|Monday, November 16, 2015|--|--|Tuesday, November 17, 2015|10:11:43|18:36:15|Wednesday, November 18, 2015|--|--|Thursday, November 19, 2015|--|--|Friday, November 20, 2015|12:14:25|20:25:08|Saturday, November 21, 2015|--|--|Sunday, November 22, 2015|--|--|Monday, November 23, 2015|10:08:08|17:57:35|Tuesday, November 24, 2015|14:30:32|--|'
**My R-Code**
====================
emp <- readChar(FileDir, (file.info(FileDir)$size-172))
emp <- gsub("\r\n","|",emp)
empTMP <- gsub('([^|]*|[^|]*|[^|]*)|',"\1\n",emp)
**output**
====================
"\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n|\001\n"
**Required output**
====================
Monday, November 2, 2015|10:21:27|17:58:12
Tuesday, November 3, 2015|10:13:09|18:52:44
Wednesday, November 4, 2015|10:11:52|18:40:36
Thursday, November 5, 2015|10:31:42|18:16:57
Friday, November 6, 2015|10:13:13|--
Saturday, November 7, 2015|--|--
Sunday, November 8, 2015|--|--
Monday, November 9, 2015|--|--
Tuesday, November 10, 2015|10:03:20|18:07:52
Wednesday, November 11, 2015|09:40:20|18:42:20
Thursday, November 12, 2015|10:38:56|18:37:20
Friday, November 13, 2015|10:45:26|18:09:54
Saturday, November 14, 2015|--|--
Sunday, November 15, 2015|--|--
Monday, November 16, 2015|--|--
Tuesday, November 17, 2015|10:11:43|18:36:15
Wednesday, November 18, 2015|--|--
Thursday, November 19, 2015|--|--
Friday, November 20, 2015|12:14:25|20:25:08
Saturday, November 21, 2015|--|--
Sunday, November 22, 2015|--|--
Monday, November 23, 2015|10:08:08|17:57:35
Tuesday, November 24, 2015|14:30:32|--
Kindly help what I am doing wrong, I check the above regular expression in text editor it works perfectly fine however in "R" it is not producing the correct result.
The following works:
#input <- #your input string
x <- strsplit(input, split = "|", fixed = TRUE)[[1L]]
idx <- seq(3L, length(x), by = 3L)
x[idx] <- paste0(x[idx], "\n")
x[-idx] <- paste0(x[-idx], "|")
paste(x, collapse = "")
Or in one command:
paste(paste0(x <- strsplit(input, split = "|", fixed = TRUE)[[1L]],
rep_len(c("|", "|", "\n"), length(x))), collapse = "")
And if you wanted to stick with gsub, this works as well:
gsub("([^|]*\\|[^|]*\\|[^|]*)\\|", "\\1\n", input)
Broken down (regex101 colored version):
gsub(paste0("(", #start capturing group 1
"[^|]*", #Matching anything but | 0 or more times
"\\|", #Match | (must escape because it's reserved for OR)
"[^|]*\\|", #again
"[^|]*", #again matching anything but |
")", #end captured group
"\\|"), #captured group is followed by a third |
"\\1\n",input) #replace match with captured group followed by \n
# (instead of |)
(just noticed your original attempt is very close. just that you forgot to escape things properly: "\\1", not "\1", and "|" is reserved so we have to escape that as well. Also #CAFEBABE is right that this seems better suited to awk...)
empTMP <- gsub('([^|]*|[^|]*|[^|]*)|',"\1\n",emp)
this is the line which causes imho the trouble.
It should be
empTMP <- gsub('([^|]*|[^|]*|[^|]*)|',"\\1\n",emp)
(note the \\1)
On the side: why do you want to use R for this task. Looks like something for standard shell scripting.
On the side 2: why teradata? On which TD box do you use R?
please, explain me, how do this thing: I have a week number (52, for example) and year (2012). So, how I can get the days number (monday - 24, tuesday - 25, etc). Yes, I read this, but I cant understand, how to do it.
Thanks.
I would do it like this:
from datetime import date, timedelta
def get_weekdays(year, week):
january_first = date(year, 1, 1)
monday_date = january_first + timedelta(days=week * 7 - january_first.weekday())
# monday, tuesday, .. sunday
return [(monday_date + timedelta(days=d)).day for d in range(7)]
(my weeks start at monday)
I see Google's example code listing dates for January, but the chart is displaying dates for February!
On my test machine, it is doing the same thing. I've told it to display dates for September, but it is displaying dates for October instead!
Can anyone else confirm this as happening?
http://code.google.com/apis/visualization/documentation/gallery/annotatedtimeline.html
The months in the javascript date are 0 based not 1 based. So 0 is Jan, 1 is Feb, etc.
See
http://www.w3schools.com/js/js_obj_date.asp
and you might want to check out
http://en.wikipedia.org/wiki/Off-by-one_error
ECMA-262 5ed, pp.165:
15.9.1.4 Month Number
Months are identified by an integer in the range 0 to 11, inclusive.
No, you're not losing your mind. The month in the Javascript Date object is zero-indexed. That means:
0 = January
1 = February
2 = March
3 = April
4 = May
5 = June
6 = July
7 = August
8 = September
9 = October
10 = November
11 = December