Need to make independent charts for current month, last month and since the beginnig of the year.

Been trying to make the table and then make the bar charts, got so far but cant seem to populate my code in order to build the tables with the specific data from a txt.

been playing arround but cant seem to do this, can someone help?

from tkinter import *
import calendar
import datetime
import numpy as np
import matplotlib.pyplot as plt

from datetime import datetime

datetime_object = datetime.strptime('Jun 1 2005  1:33PM', '%b %d %Y %I:%M%p')

root = Tk()
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
root.geometry("%dx%d+0+0" % (w, h))
root.title("week")

dt = datetime.datetime.today()
cd = calendar.Calendar()


file = open("sample.txt")
data = file.read()

lst_last_month=[]
for tipo, data in data:
    datetime_object = datetime.strptime(data, '%b %d %Y %I:%M%p')
    if startdate <= datetime_object <= enddate:
        lst_last_month.append(data)
        lst_last_month.append(tipo)

This is the expected end result

este.png

from tkinter import *
import calendar
import datetime
import numpy as np
import matplotlib.pyplot as plt

from datetime import datetime

datetime_object = datetime.strptime('Jun 1 2005  1:33PM', '%b %d %Y %I:%M%p')

root = Tk()
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
root.geometry("%dx%d+0+0" % (w, h))
root.title("week")

dt = datetime.datetime.today()
cd = calendar.Calendar()


file = open("sample.txt")
data = file.read()

lst_last_month=[]
for tipo, data in data:
    datetime_object = datetime.strptime(data, '%b %d %Y %I:%M%p')
    if startdate <= datetime_object <= enddate:
        lst_last_month.append(data)
        lst_last_month.append(tipo)






lst_dat = []
for name in calendar.month_name:
    lst_dat.append(name)


Label(root, text=lst_dat[dt.month-1], justify=RIGHT, anchor="e").grid(row=0, column=0, sticky=W, pady=1)
x=1
for l in cd.monthdayscalendar(2021, dt.month-1):
    Label(root, text=str("Week"+str(x)), justify=RIGHT, anchor="e").grid(row=x, column=0, sticky=W, pady=1)
    Label(root, text=l, justify=RIGHT, anchor="e").grid(row=x, column=1, sticky=W, pady=1)
    x += 1



Label(root, text=lst_dat[dt.month], justify=RIGHT, anchor="e").grid(row=0, column=4, sticky=W, pady=1)
x=1
for i in cd.monthdayscalendar(2021, dt.month):
    Label(root, text=str("Week"+str(x)), justify=RIGHT, anchor="e").grid(row=x, column=3, sticky=W, pady=1)
    Label(root,text=i, justify=RIGHT, anchor="e").grid(row=x, column=4,sticky=W, pady=1)
    x += 1



Label(root, text=data, justify=RIGHT, anchor="e").grid(row=0, column=10, rowspan="9999",sticky=W, pady=1)
print(data)
file.close()


class Table:

    def __init__(self, root):
        Label(root, text=lst_dat[dt.month-1], justify=RIGHT,width=20, fg='blue',font=('Arial', 26, 'bold') ,anchor="e").grid(row=8, column=0, sticky=W, pady=1)
        for i in range(total_rows):
            for j in range(total_columns):
                self.e = Entry(root, width=20, fg='blue',
                               font=('Arial', 16, 'bold'))

                self.e.grid(row=i+9, column=j)
                self.e.insert(END, lst[i][j])


        Label(root, text=lst_dat[dt.month], justify=RIGHT, width=20, fg='blue', font=('Arial', 26, 'bold'), anchor="e").grid(
            row=18, column=0, sticky=W, pady=1)
        for i in range(total_rows):
            for j in range(total_columns):
                self.e = Entry(root, width=20, fg='blue',
       ("Week2", '54', '55'),
       ("Week3", '22', '24'),
       ("Week4", '11', '12'),
       ("Week5", '37', '53')]


total_rows = len(lst)
total_columns = len(lst[0])

# create root window
t = Table(root)



if __name__ == "__main__":
    root.mainloop()

Would you mind sharing a copy of sample.txt, please? I am trying to test the program but I don't have the data file to run it.

Type Date

Reviews 24/03/21
Operations 24/03/21
Operations 24/03/21
Operations 24/03/21
Reviews 24/03/21
Operations 24/03/21
Operations 24/03/21
Reviews 24/03/21
Reviews 25/03/21
Reviews 25/03/21
Reviews 25/03/21
Reviews 25/03/21
Operations 25/03/21
Operations 25/03/21
Reviews 26/03/21
Reviews 26/03/21
Reviews 26/03/21
Reviews 29/03/21
Operations 29/03/21
Reviews 29/03/21
Reviews 29/03/21
Reviews 29/03/21
Reviews 30/03/21
Operations 30/03/21
Operations 30/03/21
Operations 30/03/21
Operations 30/03/21
Reviews 31/03/21
Reviews 01/04/21
Reviews 01/04/21
Reviews 01/04/21
Reviews 01/04/21
Reviews 01/04/21
Reviews 01/04/21
Reviews 01/04/21
Operations 01/04/21
Operations 01/04/21
Reviews 04/04/21
Reviews 05/04/21
Reviews 05/04/21
Operations 05/04/21
Operations 05/04/21
Reviews 05/04/21
Reviews 05/04/21
Reviews 05/04/21
Reviews 05/04/21
Reviews 06/04/21
Operations 06/04/21
Operations 06/04/21
Operations 06/04/21
Operations 06/04/21
Reviews 06/04/21
Reviews 06/04/21
Operations 06/04/21
Operations 06/04/21
Reviews 07/04/21
Reviews 07/04/21
Reviews 07/04/21
Reviews 07/04/21
Reviews 07/04/21
Operations 07/04/21
Reviews 07/04/21
Reviews 07/04/21
Operations 08/04/21
Operations 08/04/21
Operations 08/04/21
Operations 08/04/21
Reviews 08/04/21
Operations 08/04/21
Operations 09/04/21
Operations 12/04/21
Operations 12/04/21
Operations 12/04/21
Operations 13/04/21
Operations 13/04/21
Operations 13/04/21
Operations 13/04/21
Operations 13/04/21
Operations 13/04/21
Operations 13/04/21
Operations 13/04/21
Operations 13/04/21
Operations 13/04/21
Operations 13/04/21
Operations 13/04/21
Operations 13/04/21
Operations 13/04/21
Operations 13/04/21
Operations 13/04/21
Operations 13/04/21
Operations 13/04/21
Operations 13/04/21
Operations 13/04/21
Reviews 13/04/21
Reviews 13/04/21
Operations 13/04/21
Operations 13/04/21
Operations 13/04/21
Operations 13/04/21
Operations 13/04/21
Operations 13/04/21
Reviews 13/04/21
Operations 13/04/21
Operations 13/04/21
Operations 13/04/21
Reviews 13/04/21
Operations 14/04/21
Operations 14/04/21
Operations 14/04/21
Operations 14/04/21
Operations 14/04/21
Operations 14/04/21
Operations 14/04/21
Operations 14/04/21
Operations 14/04/21
Operations 14/04/21
Operations 14/04/21
Operations 14/04/21
Operations 15/04/21
Operations 15/04/21
Reviews 15/04/21
Reviews 15/04/21
Reviews 15/04/21
Operations 15/04/21
Operations 15/04/21
Operations 15/04/21
Reviews 15/04/21
Operations 15/04/21
Reviews 16/04/21
Operations 16/04/21
Operations 16/04/21
Operations 16/04/21
Operations 16/04/21
Reviews 16/04/21
Reviews 18/04/21
Operations 19/04/21
Operations 19/04/21
Operations 19/04/21
Operations 19/04/21
Operations 19/04/21
Operations 19/04/21
Operations 19/04/21
Operations 19/04/21
Reviews 19/04/21
Reviews 20/04/21
Operations 20/04/21
Operations 20/04/21
Operations 20/04/21
Operations 20/04/21
Reviews 21/04/21
Operations 21/04/21
Operations 21/04/21
Operations 22/04/21
Operations 22/04/21
Operations 22/04/21
Operations 22/04/21
Operations 22/04/21
Reviews 22/04/21
Reviews 22/04/21
Reviews 22/04/21
Reviews 22/04/21
Operations 23/04/21
Operations 23/04/21
Operations 23/04/21
Operations 23/04/21
Operations 23/04/21
Operations 23/04/21
Operations 23/04/21
Operations 23/04/21
Operations 23/04/21
Operations 23/04/21
Operations 25/04/21
Reviews 25/04/21
Operations 27/04/21
Operations 27/04/21
Operations 27/04/21
Operations 27/04/21
Operations 27/04/21
Operations 27/04/21
Operations 27/04/21
Operations 27/04/21
Operations 27/04/21
Operations 27/04/21
Operations 27/04/21
Operations 27/04/21
Operations 27/04/21
Operations 27/04/21
Operations 27/04/21
Operations 27/04/21
Operations 27/04/21
Operations 27/04/21
Operations 28/04/21
Operations 28/04/21
Operations 28/04/21
Operations 28/04/21
Reviews 28/04/21
Operations 28/04/21
Reviews 28/04/21
Operations 28/04/21
Operations 28/04/21
Operations 28/04/21
Operations 28/04/21
Operations 29/04/21
Operations 29/04/21
Operations 29/04/21
Operations 29/04/21
Operations 29/04/21
Operations 29/04/21
Operations 29/04/21
Operations 29/04/21
Operations 29/04/21
Operations 29/04/21
Reviews 29/04/21
Operations 29/04/21
Operations 29/04/21
Operations 29/04/21
Operations 29/04/21
Reviews 30/04/21
Operations 30/04/21
Operations 30/04/21
Operations 30/04/21
Operations 30/04/21
Operations 30/04/21
Reviews 03/05/21
Operations 03/05/21
Operations 03/05/21
Operations 03/05/21
Operations 03/05/21
Operations 03/05/21
Operations 03/05/21
Operations 03/05/21
Operations 03/05/21
Operations 03/05/21
Operations 04/05/21
Operations 04/05/21
Operations 04/05/21
Operations 04/05/21
Operations 04/05/21
Operations 04/05/21
Operations 04/05/21
Operations 05/05/21
Operations 05/05/21
Reviews 05/05/21
Operations 05/05/21
Operations 05/05/21
Reviews 05/05/21
Operations 05/05/21
Operations 05/05/21
Operations 05/05/21
Operations 05/05/21
Operations 05/05/21
Operations 06/05/21
Operations 06/05/21
Operations 06/05/21
Operations 06/05/21
Operations 06/05/21
Operations 06/05/21
Operations 06/05/21
Reviews 06/05/21
Operations 07/05/21
Operations 07/05/21
Operations 07/05/21
Operations 07/05/21
Operations 07/05/21
Operations 07/05/21
Operations 07/05/21
Reviews 10/05/21
Operations 10/05/21
Operations 10/05/21
Operations 11/05/21
Operations 11/05/21
Operations 11/05/21
Operations 11/05/21
Operations 11/05/21
Operations 11/05/21
Operations 11/05/21
Operations 11/05/21
Operations 12/05/21
Operations 12/05/21
Operations 13/05/21
Operations 13/05/21
Operations 13/05/21
Operations 13/05/21
Operations 13/05/21
Operations 13/05/21
Operations 13/05/21
Operations 14/05/21
Reviews 14/05/21
Operations 14/05/21
Operations 14/05/21
Reviews 14/05/21
Reviews 14/05/21
Reviews 14/05/21
Reviews 16/05/21
Operations 17/05/21
Operations 17/05/21
Reviews 17/05/21
Reviews 17/05/21
Reviews 17/05/21
Reviews 17/05/21
Operations 17/05/21
Operations 18/05/21
Operations 18/05/21
Reviews 18/05/21
Reviews 18/05/21
Operations 18/05/21
Operations 18/05/21
Operations 19/05/21
Operations 19/05/21
Operations 19/05/21
Operations 19/05/21
Operations 19/05/21
Operations 19/05/21
Operations 19/05/21
Operations 19/05/21
Operations 19/05/21
Operations 19/05/21
Operations 19/05/21
Operations 19/05/21
Operations 19/05/21
Operations 19/05/21
Operations 19/05/21
Operations 19/05/21
Operations 19/05/21
Operations 19/05/21
Operations 19/05/21
Reviews 19/05/21
Operations 19/05/21
Operations 19/05/21
Operations 19/05/21
Operations 20/05/21
Operations 20/05/21
Operations 20/05/21
Operations 20/05/21
Operations 20/05/21
Operations 20/05/21
Operations 21/05/21
Operations 21/05/21
Operations 21/05/21
Operations 21/05/21
Operations 21/05/21
Operations 21/05/21
Operations 21/05/21
Operations 21/05/21
Operations 21/05/21
Operations 21/05/21
Operations 24/05/21
Operations 24/05/21
Reviews 25/05/21
Reviews 25/05/21
Reviews 25/05/21
Operations 25/05/21
Operations 25/05/21
Operations 25/05/21
Operations 25/05/21
Operations 25/05/21
Operations 25/05/21
Operations 25/05/21
Operations 25/05/21
Operations 25/05/21
Operations 25/05/21
Reviews 26/05/21
Reviews 26/05/21
Operations 26/05/21
Reviews 27/05/21
Operations 27/05/21
Operations 27/05/21
Operations 27/05/21
Operations 27/05/21
Reviews 27/05/21
Reviews 27/05/21
Reviews 28/05/21
Operations 28/05/21
Operations 28/05/21
Operations 28/05/21
Operations 28/05/21
Operations 29/05/21
Operations 29/05/21
Reviews 28/06/21
Reviews 28/06/21
Operations 28/06/21
Operations 28/06/21
Operations 28/06/21
Operations 28/06/21
Operations 28/06/21
Operations 25/06/21
Operations 25/06/21
Operations 25/06/21
Operations 25/06/21
Operations 25/06/21
Operations 25/06/21
Operations 25/06/21
Reviews 25/06/21
Reviews 25/06/21
Reviews 25/06/21
Operations 25/06/21
Operations 25/06/21
Operations 25/06/21
Operations 25/06/21
Operations 25/06/21
Operations 23/06/21
Operations 23/06/21
Operations 23/06/21
Operations 23/06/21
Operations 23/06/21
Reviews 22/06/21
Operations 22/06/21
Operations 22/06/21
Operations 22/06/21
Operations 22/06/21
Operations 22/06/21
Operations 22/06/21
Operations 22/06/21
Operations 22/06/21
Operations 22/06/21
Operations 22/06/21
Operations 22/06/21
Operations 22/06/21
Operations 22/06/21
Operations 22/06/21
Operations 21/06/21
Reviews 17/06/21
Operations 17/06/21
Operations 16/06/21
Operations 16/06/21
Operations 16/06/21
Operations 16/06/21
Reviews 15/06/21
Operations 15/06/21
Operations 15/06/21
Operations 15/06/21
Operations 15/06/21
Operations 15/06/21
Operations 15/06/21
Operations 15/06/21
Operations 15/06/21
Operations 15/06/21
Reviews 14/06/21
Reviews 14/06/21
Operations 14/06/21
Operations 11/06/21
Operations 11/06/21
Operations 11/06/21
Operations 11/06/21
Operations 11/06/21
Operations 11/06/21
Operations 11/06/21
Operations 11/06/21
Operations 11/06/21
Operations 11/06/21
Operations 11/06/21
Operations 11/06/21
Operations 11/06/21
Operations 11/06/21
Operations 11/06/21
Operations 11/06/21
Operations 08/06/21
Operations 07/06/21
Operations 07/06/21
Operations 07/06/21
Operations 07/06/21
Operations 07/06/21
Operations 04/06/21
Operations 04/06/21
Reviews 04/06/21
Operations 04/06/21
Operations 04/06/21
Operations 02/06/21
Operations 02/06/21
Operations 02/06/21
Reviews 02/06/21
Operations 02/06/21
Operations 02/06/21
Operations 02/06/21
Operations 02/06/21
Operations 02/06/21
Operations 02/06/21
Operations 02/06/21
Operations 02/06/21
Operations 01/06/21
Operations 01/06/21
Operations 01/06/21
Operations 01/06/21
Operations 01/06/21
Operations 01/06/21
Operations 01/06/21
Operations 31/05/21
Operations 31/05/21
Operations 31/05/21
Operations 31/05/21
Reviews 31/05/21
Operations 09/07/21
Operations 29/06/21
Operations 29/06/21
Operations 29/06/21
Operations 29/06/21
Operations 29/06/21
Operations 09/07/21
Operations 09/07/21
Operations 08/07/21
Operations 08/07/21
Operations 08/07/21
Operations 07/07/21
Operations 07/07/21
Operations 07/07/21
Operations 06/07/21
Operations 06/07/21
Operations 06/07/21
Operations 06/07/21
Operations 06/07/21
Operations 06/07/21
Operations 05/07/21
Operations 02/07/21
Operations 02/07/21
Operations 02/07/21
Operations 02/07/21
Operations 02/07/21
Operations 01/07/21
Operations 01/07/21
Operations 01/07/21
Operations 01/07/21
Operations 01/07/21
Operations 30/06/21
Operations 30/06/21
Operations 30/06/21
Operations 30/06/21
Operations 30/06/21
Operations 30/06/21
Operations 30/06/21
Reviews 07/07/21
Reviews 06/07/21
Reviews 05/07/21
Reviews 01/07/21
Reviews 01/07/21

Thank you!

Aside from this, what problems are you having? I had to make some changes to get the code and got stuck myself, and I was wondering what specific issues you were having.

this as change a little, im getting the info not from sample.txt but from jira

this is working fine :)

from jira import JIRA

serverURL = 'https://jira.mob.dev/'
user = 'user'
password = 'pass'

options = {'server': serverURL}
jira = JIRA(options, basic_auth=(user, password))

size = 9999
initial = 0
cont = 0
while True:
    start= initial*size
    issues = jira.search_issues('project in (REV, OP)AND created >= 2021-01-01',  start,size)

    if len(issues) == 0:
        break
    initial += 1
    for issue in issues:
        print("Projecto:",issue.fields.project)
        print("Created On:",issue.fields.created)
        cont +=1

I need to make barchart from here

for i in cd.monthdayscalendar(2021, dt.month): #current month
    make chart for each week
for i in cd.monthdayscalendar(2021, dt.month-1):#last month
    make chart for each week
# form the begining of the year

Most of the solutions I'm seeing recommend using the pandas data analysis suite in conjunction withmatplotlib. Is this acceptable to you?

Similarly, there are a number of options for a Calendar widget which could be used instead of the manually aligned calendar sections, but I don't know if you wanted to use any of them.

Also, I wasn't able to connect to https://jira.mob.dev, presumably because I lacked a real username and password. I will proceed using the test data from sample.txt for now. I am assuming that the data is in the same basic format.

been making some change, this is harder than i though.
the sample data is diferente ill try to upload a file for you

from tkinter import Tk, Button, ttk
from jira import JIRA
import numpy as np
import matplotlib.pyplot as plt
import calendar
from datetime import datetime, date

root = Tk()
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
root.geometry("%dx%d+0+0" % (w, h))
root.title("week")


serverURL = 'https://jira.mob.dev/'
user = 'user'
password = 'pass'

options = {'server': serverURL}
jira = JIRA(options, basic_auth=(user, password))

c = calendar.TextCalendar(calendar.SUNDAY)
#c.prmonth(2021, 7)
cd = calendar.Calendar()


todays_date = date.today()
ano = todays_date.year
mes = todays_date.month


for i in cd.monthdayscalendar(2021, 7):
    print(i, end=" ")


print("\n\n-->"+str(len(cd.monthdayscalendar(2021, 7))))


size = 9999
initial = 0
cont = 0
lst_proj_gwf = []
lst_proj_op = []
lst_date = []

start= initial*size

projapesquisar = str("Operations, Project")
utlapesquisar1 = str("user1"), str("user2"), str("user3")
utlapesquisar2 = str("user4"), str("user5"), str("user6")
utlapesquisar = str(utlapesquisar1 + utlapesquisar2)

jsearch_current_month = jira.search_issues('project in ('+projapesquisar+') AND creator in ('+utlapesquisar+') AND created >= ' + str(ano) + '-' + str(mes) + '-01', start, size)

jsearch_last_month = jira.search_issues(
    'project in ('+projapesquisar+') AND creator in ('+utlapesquisar+') AND created >= ' + str(ano) + '-' + str(mes-1) + '-01 AND created < ' +str(ano) + '-'+ str(mes) + '-01', start, size)

jsearch_all_year = jira.search_issues(
    'project in ('+projapesquisar+') AND creator in ('+utlapesquisar+') AND created >= ' + str(ano) + '-01-01', start, size)

def get_chart(mess):
    initial = 0
    while True: 
        if len(mess) == 0:
            break
        initial += 1
        for issue in mess:
            print("Projecto:",issue.fields.project.name)#Operations or Project
            print("Created On:",issue.fields.created) #ex: 2021-6-22 00:00:00

            if "Operations" in str(issue.fields.project.name):
                lst_proj_op.append(issue.fields.project.name)
            elif "Project" in str(issue.fields.project.name):
                lst_proj_gwf.append(issue.fields.project.name)

            lst_date.append(issue.fields.created)
            cont +=1

    print(lst_proj_op)
    print("------------------")
    print(lst_proj_gwf)


    # data to plot
    n_groups = 5
    means_GWF = len(lst_proj_gwf)
    means_OP = len(lst_proj_op)

    print(means_OP)
    print(means_GWF)

    # create plot
    fig, ax = plt.subplots()
    index = np.arange(n_groups)
    bar_width = 0.35
    opacity = 0.8

    rects1 = plt.bar(index, means_GWF, bar_width,
                     alpha=opacity,
                     color='b',
                     label='GWF')

    rects2 = plt.bar(index + bar_width, means_OP, bar_width,
                     alpha=opacity,
                     color='g',
                     label='OP')

    plt.xlabel('Weeks')
    plt.ylabel('Total')
    plt.title('Current Month')
    nb=1
    weeekdays=""
    for x in cd.monthdayscalendar(2021, 7):
        print("-------->"+str(x))
        weeekdays=(weeekdays + 'Week'+str(nb)+", ")
        nb += 1

    result = ''.join(weeekdays.rsplit(', ', 1))
    print(result)
    plt.xticks(index + bar_width, (result))
    plt.legend()

    plt.tight_layout()
    plt.show()




frm = ttk.Frame(root)
frm.grid(column=0, row=0)

btn1=ttk.Button(frm, width="25", text="Current Month",command=lambda mess=jsearch_current_month: get_chart(mess)).grid(column=0, row=0, padx=10, pady=5)

btn2=ttk.Button(frm, width="25", text="Last Month",command=lambda mess=jsearch_last_month: get_chart(mess)).grid(column=0, row=1, padx=10, pady=5)

btn3=ttk.Button(frm, width="25", text="ALL Year ",command=lambda mess=jsearch_all_year: get_chart(mess)).grid(column=0, row=2, padx=10, pady=5)

Before you posted your update, I had come up with this, using the older verison of sample.txt. I don't know if it helps or not.

from tkinter import *
import calendar
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime, timedelta
#from jira import JIRA

root = Tk()
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
root.geometry("%dx%d+0+0" % (w, h))
root.title("week")

dt = datetime.today()
cd = calendar.Calendar()

file = open("sample.txt")
data_lines = file.readlines()

yearstartdate = dt.replace(month=1, day=1)
enddate = dt
if enddate.month == 1:
    startdate = enddate.replace(month=12, year=enddate.year-1)
else:
    startdate = enddate.replace(month=enddate.month-1)

year_totals = {"Total": 0}
month_totals = {"Total": 0}
last_month_totals = {"Total": 0}

for data_line in data_lines:
    tipo, date = data_line.split(' ')
    tipo = tipo.strip()
    date = date.strip()
    if date == 'Date':
        continue
    datetime_object = datetime.strptime(date.strip(), '%d/%m/%y')
    if datetime_object.year == yearstartdate.year:
        year_totals["Total"] += 1
        if tipo not in year_totals.keys():
            year_totals[tipo] = {date: 1}
        else:
            if date not in year_totals[tipo].keys():
                year_totals[tipo][date] = 1
            else:
                year_totals[tipo][date] += 1
    if (datetime_object.year == enddate.year) and (datetime_object.month == enddate.month):
        month_totals["Total"] += 1
        if tipo not in month_totals.keys():
            month_totals[tipo] = {date: 1}
        else:
            if date not in month_totals[tipo].keys():
                month_totals[tipo][date] = 1
            else:
                month_totals[tipo][date] += 1
    if (datetime_object.year == startdate.year) and (datetime_object.month == startdate.month):
        last_month_totals["Total"] += 1
        if tipo not in last_month_totals.keys():
            last_month_totals[tipo] = {date: 1}
        else:
            if date not in last_month_totals[tipo].keys():
                last_month_totals[tipo][date] = 1
            else:
                last_month_totals[tipo][date] += 1

print("Year Total: {}".format(year_totals["Total"]))
print("Current Month Total: {}".format(month_totals["Total"]))
print("Previous Month Total: {}".format(last_month_totals["Total"]))

Label(root, text=startdate.strftime("%B"), justify=CENTER, anchor="e", font=('Consolas', 16, 'bold')).grid(row=0, column=0, sticky=W, pady=1)
Label(root, text=enddate.strftime("%B"), justify=CENTER, anchor="e", font=('Consolas', 16, 'bold')).grid(row=0, column=4, sticky=W, pady=1)

for x, days in enumerate(cd.monthdayscalendar(startdate.year, startdate.month)):
    w = ''
    for day in days:
        if day == 0:
            w += '   '
        else:
            w += '{day: 3}'.format(day=day)
    print(w)
    Label(root, text="Week {0}: {1}".format(x+1, w), justify=RIGHT, anchor="e",font=('Consolas', 12, 'bold')).grid(row=x+1, column=0, sticky=W, pady=1)

for x, days in enumerate(cd.monthdayscalendar(enddate.year, enddate.month)):
    w = ''
    for day in days:
        if day == 0:
            w += '   '
        else:
            w += '{day: 3}'.format(day=day)
    print(w)
    Label(root, text="Week {0}: {1}".format(x+1, w), justify=RIGHT, anchor="e",font=('Consolas', 12, 'bold')).grid(row=x+1, column=4, sticky=W, pady=1)

#Label(root, text=lst_dat[0], justify=RIGHT, anchor="e").grid(row=0, column=10, rowspan="9999",sticky=W, pady=1)
file.close()


# create root window
#t = Table(root)


data = [year_totals["Total"], last_month_totals["Total"], month_totals["Total"]]
labels =["Year", "Prev. Month", "Current Month"] 

plt.xticks(range(len(data)), labels)
plt.xlabel('Period')
plt.ylabel('Operations')
plt.title('Operations By Period')
plt.bar(range(len(data)), data) 
plt.show()

if __name__ == "__main__":
    root.mainloop()

this is 1h in the morning, will test it tomorow.

the biggest issue is to pick a month and create the chart weekly based on that month, got it to get the weeks but cant seem to use it in order to do the query

ok, this is getting issues from jira just fine, although it dont stop :s the for loop just restart the all the issues a loaded and goes on like that.

I cant give the credentials for jira, im sorry, i just cant do that, althoug i understand and aprreciate your trying to help.

if theres any other way let me know

from tkinter import *
import calendar
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime, timedelta
from tkinter import Tk, Button, ttk
from jira import JIRA
import numpy as np
import matplotlib.pyplot as plt
import calendar
from datetime import datetime, date
#from jira import JIRA

root = Tk()
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
root.geometry("%dx%d+0+0" % (w, h))
root.title("week")

dt = datetime.today()
cd = calendar.Calendar()

yearstartdate = dt.replace(month=1, day=1)
enddate = dt
if enddate.month == 1:
    startdate = enddate.replace(month=12, year=enddate.year-1)
else:
    startdate = enddate.replace(month=enddate.month-1)

year_totals = {"Total": 0}
month_totals = {"Total": 0}
last_month_totals = {"Total": 0}

serverURL = 'https://jira.mob.dev/'
user = 'user'
password = 'pass'

options = {'server': serverURL}
jira = JIRA(options, basic_auth=(user, password))

c = calendar.TextCalendar(calendar.SUNDAY)
#c.prmonth(2021, 7)
cd = calendar.Calendar()


todays_date = date.today()
ano = todays_date.year
mes = todays_date.month


size = 9999
initial = 0
cont = 0
lst_proj_gwf = []
lst_proj_op = []
lst_date = []

start= initial*size


projapesquisar = str("GPD, OP")
utlapesquisar1 = str("user1"), str("user2"), str(
    "user3")
utlapesquisar2 = str("user4"), str("user5"), str(
    "user6")# this dont let me have them together, i have to split it :/
utlapesquisar = str(utlapesquisar1 + utlapesquisar2)

jsearch_current_month = jira.search_issues(
    'project in (' + projapesquisar + ') AND creator in (' + utlapesquisar + ') AND created >= ' + str(
        ano) + '-' + str(mes) + '-01', start, size)

jsearch_last_month = jira.search_issues(
    'project in (' + projapesquisar + ') AND creator in (' + utlapesquisar + ') AND created >= ' + str(
        ano) + '-' + str(mes - 1) + '-01 AND created < ' + str(ano) + '-' + str(mes) + '-01', start, size)

jsearch_all_year = jira.search_issues(
    'project in (' + projapesquisar + ') AND creator in (' + utlapesquisar + ') AND created >= ' + str(
        ano) + '-01-01', start, size)

def get_chart(jsearch):
    initial = 0
    while True:
        if len(jsearch) == 0:
            break
        initial += 1
        cont=0
        for issue in jsearch:
            print("Projecto:",issue.fields.project.name)
            print("Created On:",issue.fields.created)
            tipo = issue.fields.project.name.strip()
            datef = issue.fields.created.strip()
            dataspl,lixo = datef.split("T")
            datetimeobject = datetime.strptime(dataspl, '%Y-%m-%d')
            cont +=1
            print(cont)
            if date == 'Date':
                continue
            if datetimeobject.year == yearstartdate.year:
                year_totals["Total"] += 1
                if tipo not in year_totals.keys():
                    year_totals[tipo] = {date: 1}
                else:
                    if date not in year_totals[tipo].keys():
                        year_totals[tipo][date] = 1
                    else:
                        year_totals[tipo][date] += 1
            if (datetimeobject.year == enddate.year) and (datetimeobject.month == enddate.month):
                month_totals["Total"] += 1
                if tipo not in month_totals.keys():
                    month_totals[tipo] = {date: 1}
                else:
                    if date not in month_totals[tipo].keys():
                        month_totals[tipo][date] = 1
                    else:
                        month_totals[tipo][date] += 1
            if (datetimeobject.year == startdate.year) and (datetimeobject.month == startdate.month):
                last_month_totals["Total"] += 1
                if tipo not in last_month_totals.keys():
                    last_month_totals[tipo] = {date: 1}
                else:
                    if date not in last_month_totals[tipo].keys():
                        last_month_totals[tipo][date] = 1
                    else:
                        last_month_totals[tipo][date] += 1


        print("Year Total: {}".format(year_totals["Total"]))
        print("Current Month Total: {}".format(month_totals["Total"]))
        print("Previous Month Total: {}".format(last_month_totals["Total"]))

        Label(root, text=startdate.strftime("%B"), justify=CENTER, anchor="e", font=('Consolas', 16, 'bold')).grid(row=0, column=0, sticky=W, pady=1)
        Label(root, text=enddate.strftime("%B"), justify=CENTER, anchor="e", font=('Consolas', 16, 'bold')).grid(row=0, column=4, sticky=W, pady=1)

        for x, days in enumerate(cd.monthdayscalendar(startdate.year, startdate.month)):
            w = ''
            for day in days:
                if day == 0:
                    w += '   '
                else:
                    w += '{day: 3}'.format(day=day)
            print(w)
            Label(root, text="Week {0}: {1}".format(x+1, w), justify=RIGHT, anchor="e",font=('Consolas', 12, 'bold')).grid(row=x+1, column=0, sticky=W, pady=1)

        for x, days in enumerate(cd.monthdayscalendar(enddate.year, enddate.month)):
            w = ''
            for day in days:
                if day == 0:
                    w += '   '
                else:
                    w += '{day: 3}'.format(day=day)
            print(w)
            Label(root, text="Week {0}: {1}".format(x+1, w), justify=RIGHT, anchor="e",font=('Consolas', 12, 'bold')).grid(row=x+1, column=4, sticky=W, pady=1)

        #Label(root, text=lst_dat[0], justify=RIGHT, anchor="e").grid(row=0, column=10, rowspan="9999",sticky=W, pady=1)

        data = [year_totals["Total"], last_month_totals["Total"], month_totals["Total"]]
        labels =["Year", "Prev. Month", "Current Month"]

        plt.xticks(range(len(data)), labels)
        plt.xlabel('Period')
        plt.ylabel('Operations')
        plt.title('Operations By Period')
        plt.bar(range(len(data)), data)
        plt.show()


frm = ttk.Frame(root)
frm.grid(column=0, row=0)

btn1=ttk.Button(frm, width="25", text="Current Month",command=lambda jsearch=jsearch_current_month: get_chart(jsearch)).grid(column=0, row=0, padx=10, pady=5)

btn2=ttk.Button(frm, width="25", text="Last Month",command=lambda jsearch=jsearch_last_month: get_chart(jsearch)).grid(column=0, row=1, padx=10, pady=5)

btn3=ttk.Button(frm, width="25", text="ALL Year ",command=lambda jsearch=jsearch_all_year: get_chart(jsearch)).grid(column=0, row=2, padx=10, pady=5)


if __name__ == "__main__":
    root.mainloop()

I did move some of the code to two small utility functions, if you like. The first just abstracts the whole matter of getting the previous month correctly.

def prev_month(date):
    """ Returns a Datetime for the first day of the previous month.
        This is necessary to avoid underflowing on January;
        it checks for the beginning of the year and returns
        December of the previous year if the current month 
        is January."""
    if date.month == 1:
        return date.replace(month=12, year=date.year-1, day=1)
    else:
        return date.replace(month=date.month-1, day=1)

Where you would replace the existing code with:

year_start = dt.replace(month=1, day=1)
current_month = dt.replace(day=1)
last_month = prev_month(dt)

Which just cleans it up a bit.

The second is specifically regarding the JIRA searches, so I wasn't able to test it.

def jsearch_by(projects, users, start_date, end_date, start, size):
    """ Submits a query to the JIRA server and returns the results."""
    source_query = 'project in {projects} AND creator in {users}.format(projects=projects, users=users)
    date_query = 'AND created >= {start} AND created < {end}'.format(start_date.strftime("%Y-%m-01"), end_date.strftime("%Y-%m-%d"))
    query = "{}{}".format(source_query, date_query)
    return jira.search_issues(query, start, size)

You would then use this code instead of the existing searches:

projapesquisar = "(GPD, OP)"
utlapesquisar = str(["user{}".format(x) for x in range(1, 7)]).replace('[','(').replace(']',')')

jsearch_current_month = jsearch_by(projapesquisar, utlapesquisar, current_month, dt, start, size)
jsearch_last_month = jsearch_by(projapesquisar, utlapesquisar, last_month, current_month, start, size)
jsearch_all_year = jsearch_by(projapesquisar, utlapesquisar, year_start, dt, start, size)

I know this probably doesn't help much, so feel free to ignore these.

I was able to mock the JIRA issues objects in order to test the code, and got something that actually displays the wekly charts. It doesn't handle the whole year chart correctly, but it does the weekly for a given month. Let me know if this is what you needed or not.

To use it with the live data from the JIRA server, just remove the False from the call to get_issues.

from tkinter import *
import calendar
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime, timedelta
from tkinter import Tk, Button, ttk
from jira import JIRA
import numpy as np
import matplotlib.pyplot as plt
import calendar
from datetime import datetime, date


class MockProject:
    def __init__(self, name):
        self.name = name

class MockFields:
    def __init__(self, project_name, created_date):
        self.project = MockProject(project_name)
        self.created = created_date

class MockIssue:
    def __init__(self, project_name, created_date):
        self.fields = MockFields(project_name, created_date) 


def get_issues(live=True):
    jsearch_all_year = list()
    jsearch_current_month = list()
    jsearch_last_month = list()
    if live:
        serverURL = 'https://jira.mob.dev/'
        user = 'user'
        password = 'pass'
        options = {'server': serverURL}
        jira = JIRA(options, basic_auth=(user, password))
        jsearch_current_month = jsearch_by(projapesquisar, utlapesquisar, current_month, dt, start, size)
        jsearch_last_month = jsearch_by(projapesquisar, utlapesquisar, last_month, current_month, start, size)
        jsearch_all_year = jsearch_by(projapesquisar, utlapesquisar, year_start, dt, start, size)
    else:
        for data_line in data_lines:
            tipo, date, time = data_line.split()
            tipo = tipo.strip()
            date = date.strip()
            if date == 'Date':
                # skip the first line with the labels fo the columns
                continue
            # create a mocked issue
            issue = MockIssue(tipo, date)
            issue_date = datetime.strptime(date.strip(), '%Y-%m-%d')
            # accumulate issues for previous month
            if (issue_date.year == last_month.year) and (issue_date.month == last_month.month):
                jsearch_last_month.append(issue)
            # accumulate issues for current month
            elif (issue_date.year == current_month.year) and (issue_date.month == current_month.month):
                jsearch_current_month.append(issue)
            else:
                pass
            # accumulate all issues for the year
            if issue_date.year == year_start.year:
                jsearch_all_year.append(issue)
    return jsearch_last_month, jsearch_current_month, jsearch_all_year


def display_calendar(month, row, column):
        Label(root, text=month.strftime("%B"), justify=CENTER, anchor="e", font=('Consolas', 16, 'bold')).grid(row=row, column=column, sticky=W, pady=1)
        for x, days in enumerate(cd.monthdayscalendar(month.year, month.month)):
            w = ''
            for day in days:
                if day == 0:
                    w += '   '
                else:
                    w += '{day: 3}'.format(day=day)
            #print(w)
            Label(root, text="Week {0}: {1}".format(x+1, w), justify=RIGHT, anchor="e",font=('Consolas', 12, 'bold')).grid(row=x+row+1, column=column, sticky=W, pady=1)


def get_chart(jsearch):
    data = [0, 0, 0, 0, 0]
    if len(jsearch) == 0:
        return
    for issue in jsearch:
        print("Project: {}".format(issue.fields.project.name))
        print("Created On: {}".format(issue.fields.created))
        tipo = issue.fields.project.name.strip()
        datef = issue.fields.created.strip()
        issue_date = datetime.strptime(datef, '%Y-%m-%d')
        data[week_number_of_month(issue_date) - 1] += 1

    labels =["Week {}".format(x) for x in range(1, 6)]

    plt.xticks(range(len(data)), labels)
    plt.xlabel('Period')
    plt.ylabel('Operations')
    plt.title('Operations By Period')
    plt.bar(range(len(data)), data)
    plt.show()


def prev_month(date):
    """ Returns a Datetime for the first day of the previous month.
        This is necessary to avoid underflowing on January;
        it checks for the beginning of the year and returns
        December of the previous year if the current month 
        is January."""
    if date.month == 1:
        return date.replace(month=12, year=date.year-1, day=1)
    else:
        return date.replace(month=date.month-1, day=1)


def jsearch_by(projects, users, start_date, end_date, start, size):
    """ Submits a query to the JIRA server and returns the results."""
    source_query = 'project in {projects} AND creator in {users}'.format(projects=projects, users=users)
    date_query = 'AND created >= {start} AND created < {end}'.format(start_date.strftime("%Y-%m-01"), end_date.strftime("%Y-%m-%d"))
    query = "{}{}".format(source_query, date_query)
    return jira.search_issues(query, start, size)


def week_number_of_month(date_value):
    """ Compute which week of the month a given date is in. 
    Taken from the page at https://www.mytecbits.com/internet/python/week-number-of-month."""
    return (date_value.isocalendar()[1] - date_value.replace(day=1).isocalendar()[1] + 1)



if __name__ == "__main__":
    root = Tk()
    w, h = root.winfo_screenwidth(), root.winfo_screenheight()
    root.geometry("{width}x{height}+0+0".format(width=w, height=h))
    root.title("week")

    dt = datetime.today()
    cd = calendar.Calendar()

    year_start = dt.replace(month=1, day=1)
    current_month = dt.replace(day=1)
    last_month = prev_month(current_month)

    c = calendar.TextCalendar(calendar.SUNDAY)
    cd = calendar.Calendar()

    todays_date = date.today()
    ano = todays_date.year
    mes = todays_date.month

    size = 9999
    initial = 0
    start = initial * size

    projapesquisar = "(GPD, OP)"
    utlapesquisar = str(["user{}".format(x) for x in range(1, 7)]).replace('[','(').replace(']',')')

    file = open("samples.txt")
    data_lines = file.readlines()

    frm = ttk.Frame(root)
    frm.grid(column=0, row=0)

    display_calendar(last_month, 0, 2)
    display_calendar(current_month, 0, 6)

    jsearch_last_month, jsearch_current_month, jsearch_all_year = get_issues(False)


    btn1=ttk.Button(frm, width="25", text="Current Month",command=lambda jsearch=jsearch_current_month: get_chart(jsearch)).grid(column=0, row=0, padx=10, pady=5)

    btn2=ttk.Button(frm, width="25", text="Last Month",command=lambda jsearch=jsearch_last_month: get_chart(jsearch)).grid(column=0, row=1, padx=10, pady=5)

    btn3=ttk.Button(frm, width="25", text="ALL Year ",command=lambda jsearch=jsearch_all_year: get_chart(jsearch)).grid(column=0, row=2, padx=10, pady=5)

    root.mainloop()

I've made some additional cleanup changes, but I'll hold off on posting those until I hear back from Razstec about the verison I just posted.

Contrary to what I said earlier, I am now posting the most recent modifications to the code. Hope this helps.

from tkinter import *
import calendar
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime, timedelta
from tkinter import Tk, Button, ttk
from jira import JIRA
import numpy as np
import matplotlib.pyplot as plt
import calendar
from datetime import datetime, date


class MockProject:
    def __init__(self, name):
        self.name = name

class MockFields:
    def __init__(self, project_name, created_date):
        self.project = MockProject(project_name)
        self.created = created_date

class MockIssue:
    def __init__(self, project_name, created_date):
        self.fields = MockFields(project_name, created_date) 

def get_issues(live=True):
    """ Get a set of JIRA issues for a given time period.
        For testing purposes, it can instead get data from 
        a data file 'sample.txt' and mocking up the JIRA
        issue data structure."""
    jsearch_all_year = list()
    jsearch_current_month = list()
    jsearch_last_month = list()
    if live:
        serverURL = 'https://jira.mob.dev/'
        user = 'user'
        password = 'pass'
        options = {'server': serverURL}
        jira = JIRA(options, basic_auth=(user, password))

        projapesquisar = "(GPD, OP)"
        utlapesquisar = str(["user{}".format(x) for x in range(1, 7)]).replace('[','(').replace(']',')')

        jsearch_current_month = jsearch_by(projapesquisar, utlapesquisar, current_month, dt, start, size)
        jsearch_last_month = jsearch_by(projapesquisar, utlapesquisar, last_month, current_month, start, size)
        jsearch_all_year = jsearch_by(projapesquisar, utlapesquisar, year_start, dt, start, size)
    else:
        file = open("sample.txt")
        data_lines = file.readlines()
        for data_line in data_lines:
            tipo, date, time = data_line.split()
            tipo = tipo.strip()
            date = date.strip()
            if date == 'Date':
                # skip the first line with the labels fo the columns
                continue
            # create a mocked issue
            issue = MockIssue(tipo, date)
            issue_date = datetime.strptime(date.strip(), '%Y-%m-%d')
            # accumulate issues for previous month
            if (issue_date.year == last_month.year) and (issue_date.month == last_month.month):
                jsearch_last_month.append(issue)
            # accumulate issues for current month
            elif (issue_date.year == current_month.year) and (issue_date.month == current_month.month):
                jsearch_current_month.append(issue)
            else:
                pass
            # accumulate all issues for the year
            if issue_date.year == year_start.year:
                jsearch_all_year.append(issue)
    return jsearch_last_month, jsearch_current_month, jsearch_all_year


def display_calendar(root, calendar, month, row, column):
    Label(root, text=month.strftime("%B"), justify=CENTER, anchor="e", font=('Consolas', 16, 'bold')).grid(row=row, column=column, sticky=W, pady=1)
    for x, days in enumerate(calendar.monthdayscalendar(month.year, month.month)):
        w = ''
        for day in days:
            if day == 0:
                w += '   '
            else:
                w += '{day: 3}'.format(day=day)
                #print(w)
        Label(root, text="Week {0}: ".format(x+1), justify=RIGHT, anchor="e",font=('Consolas', 12, 'bold')).grid(row=x+row+1, column=column, sticky=W, pady=1)
        Label(root, text="{0}".format(w), justify=RIGHT, anchor="e",font=('Consolas', 12, 'bold')).grid(row=x+row+1, column=column+1, sticky=W, pady=1)


def get_chart(jsearch, period_name):
    """ Generates a Matplotlib bar chart window from the list of JIRA issues."""
    if period_name == "All Weeks":
        data = [0 for x in range(1, 53)]
    else:
        data = [0, 0, 0, 0, 0]
    if len(jsearch) == 0:
        return
    for issue in jsearch:
        tipo = issue.fields.project.name.strip()
        datef = issue.fields.created.strip()
        issue_date = datetime.strptime(datef, '%Y-%m-%d')    
        if period_name == "All Weeks":
            labels = range(1, 53)
            data[week_number_of_year(issue_date) - 1] +=1
        else:
            labels =["Week {}".format(x) for x in range(1, 6)]
            data[week_number_of_month(issue_date) - 1] += 1
    plt.xticks(range(len(data)), labels)
    plt.xlabel('Week')
    plt.ylabel('Operations')
    plt.title('Operations for {}'.format(period_name))
    plt.bar(range(len(data)), data)
    plt.show()


def prev_month(date):
    """ Returns a Datetime for the first day of the previous month.
        This is necessary to avoid underflowing on January;
        it checks for the beginning of the year and returns
        December of the previous year if the current month 
        is January."""
    if date.month == 1:
        return date.replace(month=12, year=date.year-1, day=1)
    else:
        return date.replace(month=date.month-1, day=1)


def jsearch_by(projects, users, start_date, end_date, start, size):
    """ Submits a query to the JIRA server and returns the results."""
    source_query = 'project in {projects} AND creator in {users}'.format(projects=projects, users=users)
    date_query = 'AND created >= {start} AND created < {end}'.format(start_date.strftime("%Y-%m-01"), end_date.strftime("%Y-%m-%d"))
    query = "{}{}".format(source_query, date_query)
    return jira.search_issues(query, start, size)


def week_number_of_month(date_value):
    """ Compute which week of the month a given date is in. 
    Taken from the page at https://www.mytecbits.com/internet/python/week-number-of-month."""
    return (date_value.isocalendar()[1] - date_value.replace(day=1).isocalendar()[1] + 1)

def week_number_of_year(date_value):
    """ Compute which week of the month a given date is in. 
    Taken from the page at https://www.mytecbits.com/internet/python/week-number-of-month."""
    return int(date_value.strftime("%W"))

if __name__ == "__main__":
    root = Tk()
    w, h = root.winfo_screenwidth(), root.winfo_screenheight()
    root.geometry("{width}x{height}+0+0".format(width=w, height=h))
    root.title("week")

    todays_date = datetime.today()
    cd = calendar.Calendar()

    year_start = todays_date.replace(month=1, day=1)
    current_month =  todays_date.replace(day=1)
    last_month = prev_month(current_month)

    frm = ttk.Frame(root)
    frm.grid(column=0, row=0)

    display_calendar(root, cd, last_month, 0, 2)
    display_calendar(root, cd, current_month, 0, 4)

    jsearch_last_month, jsearch_current_month, jsearch_all_year = get_issues(False)

    btn = list()
    btn.append(ttk.Button(frm, width="25", text="Current Month",command=lambda jsearch=jsearch_current_month, period=current_month.strftime("%B"): get_chart(jsearch, period)).grid(column=0, row=0, padx=10, pady=5))
    btn.append(ttk.Button(frm, width="25", text="Last Month",command=lambda jsearch=jsearch_last_month, period=last_month.strftime("%B"): get_chart(jsearch, period)).grid(column=0, row=1, padx=10, pady=5))
    btn.append(ttk.Button(frm, width="25", text="All Month Weeks",command=lambda jsearch=jsearch_all_year, period="All Year": get_chart(jsearch, period)).grid(column=0, row=2, padx=10, pady=5))
    btn.append(ttk.Button(frm, width="25", text="All Weeks of Year",command=lambda jsearch=jsearch_all_year, period="All Weeks": get_chart(jsearch, period)).grid(column=0, row=3, padx=10, pady=5))

    root.mainloop()

wow, thanks

just having an issue with the start

File "/Users/ricardosimoes/PycharmProjects/OCPP/week_report.py", line 137, in jsearch_by
    date_query = 'AND created >= {start} AND created < {end}'.format(start_date.strftime("%Y-%m-01"), end_date.strftime("%Y-%m-%d"))

KeyError: 'start'

I had this to the if name == "main":

    dt = datetime.today()

    size = 9999
    initial = 0
    start = initial * size

but still get this error

Huh, I don't know why that wasn't showing up for me earlier, but I do see what is happening. I used two keywords in the formatting string, but didn't give the keyword names in the format command. The correct version should be:

 date_query = 'AND created >= {start} AND created < {end}'.format(start=start_date.strftime("%Y-%m-01"), end=end_date.strftime("%Y-%m-%d"))

Sorry about that. I hope it works now.

thank you :)

now i get this odd error

def jsearch_by(projects, users, start_date, end_date, start, size):
    """ Submits a query to the JIRA server and returns the results."""
    source_query = 'project in {projects} AND creator in {users}'.format(projects=projects, users=users)
    date_query = 'AND created >= {start} AND created < {end}'.format(start=start_date.strftime("%Y-%m-01"),end=end_date.strftime("%Y-%m-%d"))
    query = "{}{}".format(source_query, date_query)
    return jira.search_issues(query, start, size). <------- error






      File "/Users/ricardosimoes/PycharmProjects/OCPP/week_report.py", line 139, in jsearch_by
        return search_issues(query, start, size)
    NameError: name 'jira' is not defined

change jira to JIRA and the error changed

 File "/Users/ricardosimoes/PycharmProjects/OCPP/week_report.py", line 139, in jsearch_by
    return JIRA.search_issues(query, start, size)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/jira/client.py", line 2501, in search_issues
    if self._fields:

AttributeError: 'str' object has no attribute '_fields'

Any idea??

Could you try this, please?

def jsearch_by(jira, projects, users, start_date, end_date, start, size):
    """ Submits a query to the JIRA server and returns the results."""
    source_query = 'project in {projects} AND creator in {users}'.format(projects=projects, users=users)
    date_query = 'AND created >= {start} AND created < {end}'.format(start=start_date.strftime("%Y-%m-01"), end=end_date.strftime("%Y-%m-%d"))
    query = "{}{}".format(source_query, date_query)
    return jira.search_issues(query, start, size)

You'll need to add the jira argument to the calls to jsearch_by() as well. This was an oversight on my part, sorry.

it seems there is a date not converted

    raise ValueError("unconverted data remains: %s" %

ValueError: unconverted data remains: T13:13:01.000+0000

i think is this issue_date

       for issue in jsearch:
        tipo = issue.fields.project.name.strip()
        datef = issue.fields.created.strip()
        issue_date = datetime.strptime(datef, '%Y-%m-%d')

    if period_name == "All Weeks":

date is send by jira in this format

datef=2021-07-16T13:13:01.000+0000

OK, I think this should work, replace the previous assignment to issue_date with

issue_date = datetime.fromisoformat(datef)

This assumes that the dates are in ISO format, which I gather they will be.

This documentation page may be of use here.

commented: :( issue_date = datetime.fromisoformat(datef) ValueError: Invalid isoformat string: '2021-07-16T13:13:01.000+0000' +2

:( issue_date = datetime.fromisoformat(datef) ValueError: Invalid isoformat string: '2021-07-16T13:13:01.000+0000'

Damn, that's frustrating. You might need to install and use the dateutil, which can parse aribtrary date and time formats. I'll read up on it myself and see if I can find an answer.

from dateutil.parser import *
# ...
        issue_date = parse(datef)
commented: been reading, i think its because of the parse +0

That last part is a UTC time zone offset, which can be parsed with the format substring %z.

issue_date = datetime.strptime(datef, "%Y-%m-%dT%H:%M:%S.%f%z")

I also edited a previous message, but the relevant part is that Dateutil.parser.parse.parse() may be

from dateutil.parser import *
# ...
        issue_date = parse(datef)

done it :)
issue_date = datetime.strptime(datef, "%Y-%m-%dT%H:%M:%S.%f%z")

but now :(

  if period_name == "All Weeks":
            labels = range(1, 53)
            data[week_number_of_year(issue_date) - 1] +=1
        else:
            labels =["Week {}".format(x) for x in range(1, 6)]

        data[week_number_of_month(issue_date) - 1] += 1




          File "/Users/ricardosimoes/PycharmProjects/OCPP/week_report.py", line 116, in get_chart
data[week_number_of_month(issue_date) - 1] += 1
IndexError: list index out of range

facepalm OK, according to a comment on the page I got the code for week_number_of_month(), there is a known bug in datetime.datetime().date() which will cause it to return a negative value for certain dates in the last week of the month. I don't know if this is actually the case, but we might be able to see what is happening here if you could add this line just before that, so we can see what the value it is choking on is.

            print(week_number_of_month(issue_date))

This kludge might fix the problem:

def week_number_of_month(date_value):
    """ Compute which week of the month a given date is in. 
    Taken from the page at https://www.mytecbits.com/internet/python/week-number-of-month."""
    ret_date = date_value.isocalendar()[1] - date_value.replace(day=1).isocalendar()[1] + 1
    if ret_date >= 1:
        return ret_date
    else:
        return 5

it reply this :s

/usr/local/bin/python3.9 /Users/ricardosimoes/PycharmProjects/OCPP/week_report.py
4
4
4
4
4
4
4
4
4
4
4
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
1
1
1
1
1
1
1
1
1
3
3
3
3
2
2
2
1
1
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
5
5
5
5
5
5
5
4
4
4
4
3
3
3
3
2
2
2
2
2
2
1
1
4
4
4
4
4
4
4
4
4
4
4
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
1
1
1
1
1
1
1
1
1
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

6

strange, same error

 File "/Users/ricardosimoes/PycharmProjects/OCPP/week_report.py", line 117, in get_chart
    data[week_number_of_month(issue_date) - 1] += 1

IndexError: list index out of range
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.