Hi guys I am having the same errors:
def findActivity(choice):
if choice>=1 and choice<=100:
return 'Recovery'
elif choice >100 and choice <=200:
return 'Preparative'
elif choice >=180 and choice <=325:
return 'Organizational'
elif choice >=300 and choice <=450:
return 'Maintenance'
elif choice >450 and choice <=640:
return 'Thresold'
elif choice >=640 and choice <=900:
return 'Fitness'
elif choice >=810 and choice <=1200:
return 'Game'
else:
return "Training"
def idFunction(year,ind, indexList, i, days, weekDay):
if ind==0 and days[weekDay][ind] not in [1,2,3,4,5,6]:
if i==1:
m_id=date(year-1, 12, days[weekDay][ind])
else:
m_id=date(year, i-1, days[weekDay][ind])
elif ind==indexList[-1] and days[weekDay][ind] not in [24,25,26,27,28,29, 30,31]:
if i==12:
m_id=date(year+1, 1, days[weekDay][ind])
else:
m_id=date(year, i+1, days[weekDay][ind])
else:
m_id=date(year, i, days[weekDay][ind])
return m_id
def activity(d):
year=int(d[0:4])
month=int(d[5:7])
day=int(d[8:])
c = conn.cursor()
c.execute('SELECT activity FROM planner WHERE date=%s and teamName =%s', (datetime.date(year,month,day),"UCF"))
result = c.fetchone()#fetchall
c.execute('SELECT first, last, sum(load) AS load FROM "UCF_Women_Soccer_DEV".ff90_training_load WHERE date=%s GROUP BY first, last', (datetime.date(year,month,day),))
result2 = c.fetchall()
if result:
return result[0]#result[0]
elif result2:
load=[value for first, last, value in result2]
mode=statistics.mode(load)
return findActivity(mode)
else:
return "OFF"
my_calendar = html.Div([
dbc.Row(
dbc.Col(
dcc.Dropdown(
id="month",
options=[{
"label": x,
"value": x
} for x in calendar.month_name],
value=calendar.month_name[date.today().month],
clearable=False,
))),
html.Br(),
])
years = html.Div([
dbc.Row(
dbc.Col(
dcc.Dropdown(
id="years",
options=[{
"label": x,
"value": x
} for x in range(2000,2100)],
value=2021,
clearable=False,
))),
html.Br(),
])
table_header = [
html.Thead(html.Tr([html.Th("KEY"), html.Th(dbc.Badge("RECOVERY", color="primary")), html.Th(dbc.Badge("PREPARATIVE", color="success")), html.Th(dbc.Badge("ORGANIZATIONAL", color="warning")), html.Th(dbc.Badge("MAINTENANCE", color="info")), html.Th(dbc.Badge("THRESOLD", color="light")), html.Th(dbc.Badge("FITNESS", color="dark")), html.Th(dbc.Badge("GAME", color="danger")) ]))
]
row1 = html.Tr([html.Td("RPE"), html.Td("<3"),html.Td("3-4"), html.Td("4-5"), html.Td("5-6"), html.Td("7-8"), html.Td("8-9"), html.Td("9-10")])
row2 = html.Tr([html.Td("VOL"), html.Td("<35min"), html.Td("35-45min"), html.Td("45-60min"), html.Td("45-75min"), html.Td("75-80min"), html.Td("80-100min"), html.Td("90min")])
row3 = html.Tr([html.Td("TL"), html.Td("<100"), html.Td("105-200"), html.Td("180-325"), html.Td("300-450"), html.Td("490-640"), html.Td("640-900"), html.Td(">810")])
row4 = html.Tr([html.Td("Readiness"), html.Td("<65"), html.Td(">77.5"), html.Td("66-75"), html.Td("70-80"), html.Td("75-85"), html.Td("82.5-95"), html.Td("87.5")])
row5 = html.Tr([html.Td("Recovery"), html.Td("n/a"), html.Td("12hr"), html.Td("<24hr"), html.Td("24hr"), html.Td("48hr"), html.Td("72hr"), html.Td(">72hr")])
table_body = [html.Tbody([row1, row2, row3, row4, row5])]
table = dbc.Table(table_header + table_body, bordered=True,
hover=True,
responsive=True,
striped=True,)
DATABASE_URL = 'postgres://panjfsdgbbpqjp:e82392fdcc0e809c9ee02a9459d9da3e0e414094bdbc8f88acb69d3f7686da5a@ec2-52-44-31-100.compute-1.amazonaws.com:5432/d2itj4h57p7v0h'
conn = psycopg2.connect(DATABASE_URL, sslmode='require')
options6=["Highest Training Load", "Lowest Training Load"]
colors = {
'background': '#ffffed',
'text': '#7FDBFF'
}#style={'backgroundColor': colors['background']},
def layout():
return html.Div(children=[
#html.Div(my_calendar, id='monthChoice'),
dbc.Row(html.H1("Planner"), className="container_title",),
html.Br(),
html.Div(dbc.Row([dbc.Col(html.H4("Team average", style={
'textAlign': 'left',
})), dbc.Col(html.Div([dbc.Row(html.H4("Last 7 days")),dcc.Dropdown(
id="LastSevenDays",
options=[{
"label": x,
"value": x
} for x in options6],
value=options6[0],
clearable=False,
), html.Div(id="LastSevenDayOutput")], className="container_title"))])),
html.Br(),html.Br(),
html.Div([dbc.Row([dbc.Col(my_calendar), dbc.Col(years)], no_gutters=True),
dbc.Row([
dbc.Col(
[html.Div("Monday"),
])
], no_gutters=True)], style={
"width": "98%",
"margin-right": "0",
}),html.Br(),html.Br(),html.Div(table),html.Br(),
dbc.Row([dbc.Col(html.Div(id="day-activity", style={'overflowY':'scroll', 'height':400, 'width':500})),dbc.Col(dcc.Graph(id='forecast', style={'display': 'none'}))]),
html.Div(id="output2-container", children=[], style={'display': 'none'}),
html.Div(id='dropdownChoice'),
html.Div(id='Output6', style={'display': 'none'}),
])
@app.callback(Output("LastSevenDayOutput", "children"), Input("LastSevenDays", "value"))
def lastSevenDaysOutput(choice):
c = conn.cursor()
if choice=="Highest Training Load":
c.execute('select first || \' \'|| last as player_name, sum(load) as Training_load \
from "UCF_Women_Soccer_DEV".ff90_training_load \
where date >\'' + "2021-02-28" + '\' and date <= \'' + "2021-03-7"+ '\' \
group by ROLLUP (player_name) order by Training_load DESC LIMIT 6')
else:
c.execute('select first || \' \'|| last as player_name, sum(load) as Training_load \
from "UCF_Women_Soccer_DEV".ff90_training_load \
where date >\'' + "2021-02-28" + '\' and date <= \'' + "2021-03-7"+ '\' \
group by ROLLUP (player_name) order by Training_load LIMIT 5')
result=c.fetchall()
row=[]
names=[]
load=[]
if result:
for i in result:
if i[0] ==None:
continue
j=i[1]/7
j=round(j,1)
names.append(i[0])
load.append(j)
#row.append(dbc.Row([dbc.Col(i[0]), dbc.Col(j)]))
list_of_tuples = list(zip(names, load))
df = pd.DataFrame(list_of_tuples,
columns = ['Name', '7 Days average'])
return dash_table.DataTable(
id='table',
columns=[{"name": i, "id": i} for i in df.columns],
data=df.to_dict('records'),
)
return row
@app.callback([Output("monday", "children") ], [Input("month", "value"), Input("years", "value")])
def displayCalendar(value, yearss):
df = [
"January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"
]
data1 = [
'Preparative', 'Organizational', 'Maintenance', 'Thresold', 'Fitness',
'Game', 'Recovery'
]
for i, month in enumerate(df):
if month == value:
break
i = i + 1
print(i)
days = calendar.monthcalendar(yearss, i)
if i==1:
previousMonth=calendar.monthcalendar(yearss-1, 12)
else:
previousMonth=calendar.monthcalendar(yearss, i-1)
if i==12:
nextMonth=calendar.monthcalendar(yearss+1, 1)
else:
nextMonth=calendar.monthcalendar(yearss, i+1)
a=0
for j in days[0]:
if j ==0:
days[0][a]=previousMonth[-1][a]
a+=1
a=0
for j in days[-1]:
if j ==0:
days[-1][a]=nextMonth[0][a]
a+=1
monday = []
data1 = [
'Preparative', 'Organizational', 'Maintenance', 'Thresold', 'Fitness',
'Game', 'Recovery', 'OFF'
]
j = days
days = pd.DataFrame(days)
days.columns = [
'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
'Sunday'
]
for ind in days.index:
m_id=str(idFunction(yearss,ind, days.index, i, days, 'Monday'))
m_act=activity(m_id)
if days['Monday'][ind] != 0:
monday.append(
dbc.Card(
dbc.CardBody([
html.Div(
dbc.Button(children=days['Monday'][ind],
id={
'type': 'date-button',
'index': m_id
},
color="link")),
dcc.Dropdown(
id={
'type': 'dropdown2',
'index': m_id },
options=[{
"label": x,
"value": x
} for x in data1],
value=m_act,
clearable=False,
)
])))
monday.append(dcc.Store(id='permanent-date'))
monday.append(dcc.Store(id='permanent-object'))
monday.append(dcc.ConfirmDialog(
id='confirm',
message='Doing this change might override training specification, are you sure you want to continue?',
))
return monday
I have a multi page daash app, and I get the error when I come at the page with this code