binaychandra commited on
Commit
598defd
·
1 Parent(s): 71937e4

static changes

Browse files
Files changed (1) hide show
  1. draft_mailscript.py +12 -12
draft_mailscript.py CHANGED
@@ -86,12 +86,12 @@ def bookingcomparison_year2019(qmodel_df : pd.DataFrame()) -> str:
86
  fig.update_layout(geo=dict(showlakes=False, lakecolor = 'rgba(0,0,0,0)', bgcolor= 'rgba(0,0,0,0)'))
87
  fig.update_layout(geo=dict(scope='usa', showlakes=False))
88
  fig.update_traces(showlegend=True)
89
- fig.write_image("./static/images/usmap_percentchangefrmyear2019.png", engine='kaleido',format='png')
90
  # resize the image to fit in the cell
91
- im = Image.open('./static/images/usmap_percentchangefrmyear2019.png')
92
  width, height = im.size
93
  im1 = im.crop((100, 100, 600, 390)) #set the crop coordinates (x,y, x+width, y+height)
94
- im1.save('./static/images/usmap_percentchangefrmyear2019.png')
95
 
96
  # Gather observations ___________
97
  observations_thisweekvsyear2019 = ["The overall bookings this week {isincreased} compared to 2019 by {percentincordec}%".format(isincreased = 'increased' if thisweekvsyear2019.percentchangefrom2019.sum() > 0 else 'decreased', percentincordec = round(abs(thisweekvsyear2019.percentchangefrom2019.mean()), 2))]
@@ -165,12 +165,12 @@ def bookingcomparison_previousweek(qmodel_df: pd.DataFrame()) -> str:
165
  fig.update_layout(coloraxis_showscale=False)
166
  fig.update_layout(geo=dict(showlakes=False, lakecolor = 'rgba(0,0,0,0)', bgcolor= 'rgba(0,0,0,0)'))
167
  fig.update_layout(geo=dict(scope='usa', showlakes=False))
168
- fig.write_image("./static/images/usmap_percentchangefrmlastweek.png", engine='kaleido',format='png')
169
 
170
- im = Image.open('./static/images/usmap_percentchangefrmlastweek.png')
171
  width, height = im.size
172
  im1 = im.crop((100, 100, 600, 390)) #set the crop coordinates (x,y, x+width, y+height)
173
- im1.save('./static/images/usmap_percentchangefrmlastweek.png')
174
 
175
  # Gather observations ___________
176
  observations_thisweekvslastweek = ["The overall bookings this week {isincreased} from the previous week by {percentincordec}%".format(isincreased = 'increased' if thisweekvslastweek.percentchangefromlastweek.sum() > 0 else 'decreased', percentincordec = round(thisweekvslastweek.percentchangefromlastweek.mean(), 2))]
@@ -239,13 +239,13 @@ def actualbookingstats(qmodel_df : pd.DataFrame()) -> str:
239
  fig.update_layout({'plot_bgcolor': 'rgba(0, 0, 0, 0)','paper_bgcolor': 'rgba(0, 0, 0, 0)'}, xaxis = dict(tickmode = 'linear', tickangle = -45, tick0 = dlatest.Date[0],
240
  dtick = 30), legend=dict(orientation="h", yanchor="bottom", y=0.85, xanchor="left", x=0.05, font = dict(size=10)))
241
  print("Layout updated ")
242
- fig.write_image(r"./static/images/dailybooking_lineplot.png", engine='kaleido',format='png', height=400, width = 600)
243
  # resize the image to fit in the cell - plot_bgcolor = "rgba(211, 245, 244,0.5)",
244
  print("image written")
245
- im = Image.open('./static/images/dailybooking_lineplot.png')
246
  width, height = im.size
247
  im1 = im.crop((50, 75, 570, 390)) #set the crop coordinates (x,y, x+width, y+height)
248
- im1.save('./static/images/dailybooking_lineplot.png')
249
  bookingstats = []
250
  bookingstats.append("The average number of booking per day is {perdaybooking2021} which is {percentdiff20n21:.1f}% {highorlow20n21} than 2020 {andorbut} {percentdiff21n19:.1f}% {highorlow21n19} than year 2019."\
251
  .format(perdaybooking2021= format(int(dlatest21.ActualBooking.mean()), ','),
@@ -289,7 +289,7 @@ def statewiseanalysis_ytd(qmodel_df: pd.DataFrame()) -> str:
289
  fig.update_layout({'plot_bgcolor': 'rgba(0, 0, 0, 0)','paper_bgcolor': 'rgba(0, 0, 0, 0)'})
290
  # fig.update_traces(textposition='inside', textinfo='percent+label')
291
  # fig.update_layout(coloraxis_showscale=False)
292
- fig.write_image("./static/images/pie_statesytd.png", engine='kaleido',format='png')
293
 
294
  highstatelist = ', '.join([item for item in avgBookings_state.State[:5].values])
295
  last_char_index = highstatelist.rfind(",")
@@ -335,7 +335,7 @@ def divisionwiseanalysis(qmodel_df: pd.DataFrame) -> str:
335
  fig.update_layout({'plot_bgcolor': 'rgba(0, 0, 0, 0)','paper_bgcolor': 'rgba(0, 0, 0, 0)'},
336
  xaxis = dict(tickmode = 'linear', tickangle = -45),
337
  legend=dict(orientation="h", yanchor="bottom", y=0.95, xanchor="right", x=1, font = dict(size=10)))
338
- fig.write_image(r"./static/images/dailybookingdivision_barplot.png", engine='kaleido',format='png', height=400, width = 600)
339
 
340
  df192021['pChangein1921'] = (df192021['2021'] - df192021['2019']) * 100 / df192021['2019']
341
  df192021['pChangein2021'] = (df192021['2021'] - df192021['2020']) * 100 / df192021['2019']
@@ -383,7 +383,7 @@ def sendmail_html(htmlcontent: str) -> None:
383
  msgAlternative.attach(msgText)
384
 
385
  # We reference the image in the IMG SRC attribute by the ID we give it below
386
- pngfileslist = glob(r'./static/images/*.png')
387
  for pngfile in pngfileslist:
388
  with open(pngfile, 'rb') as fp:
389
  msgImage = MIMEImage(fp.read())
 
86
  fig.update_layout(geo=dict(showlakes=False, lakecolor = 'rgba(0,0,0,0)', bgcolor= 'rgba(0,0,0,0)'))
87
  fig.update_layout(geo=dict(scope='usa', showlakes=False))
88
  fig.update_traces(showlegend=True)
89
+ fig.write_image("/code/static/images/usmap_percentchangefrmyear2019.png", engine='kaleido',format='png')
90
  # resize the image to fit in the cell
91
+ im = Image.open('/code/static/images/usmap_percentchangefrmyear2019.png')
92
  width, height = im.size
93
  im1 = im.crop((100, 100, 600, 390)) #set the crop coordinates (x,y, x+width, y+height)
94
+ im1.save('/code/static/images/usmap_percentchangefrmyear2019.png')
95
 
96
  # Gather observations ___________
97
  observations_thisweekvsyear2019 = ["The overall bookings this week {isincreased} compared to 2019 by {percentincordec}%".format(isincreased = 'increased' if thisweekvsyear2019.percentchangefrom2019.sum() > 0 else 'decreased', percentincordec = round(abs(thisweekvsyear2019.percentchangefrom2019.mean()), 2))]
 
165
  fig.update_layout(coloraxis_showscale=False)
166
  fig.update_layout(geo=dict(showlakes=False, lakecolor = 'rgba(0,0,0,0)', bgcolor= 'rgba(0,0,0,0)'))
167
  fig.update_layout(geo=dict(scope='usa', showlakes=False))
168
+ fig.write_image("/code/static/images/usmap_percentchangefrmlastweek.png", engine='kaleido',format='png')
169
 
170
+ im = Image.open('/code/static/images/usmap_percentchangefrmlastweek.png')
171
  width, height = im.size
172
  im1 = im.crop((100, 100, 600, 390)) #set the crop coordinates (x,y, x+width, y+height)
173
+ im1.save('/code/static/images/usmap_percentchangefrmlastweek.png')
174
 
175
  # Gather observations ___________
176
  observations_thisweekvslastweek = ["The overall bookings this week {isincreased} from the previous week by {percentincordec}%".format(isincreased = 'increased' if thisweekvslastweek.percentchangefromlastweek.sum() > 0 else 'decreased', percentincordec = round(thisweekvslastweek.percentchangefromlastweek.mean(), 2))]
 
239
  fig.update_layout({'plot_bgcolor': 'rgba(0, 0, 0, 0)','paper_bgcolor': 'rgba(0, 0, 0, 0)'}, xaxis = dict(tickmode = 'linear', tickangle = -45, tick0 = dlatest.Date[0],
240
  dtick = 30), legend=dict(orientation="h", yanchor="bottom", y=0.85, xanchor="left", x=0.05, font = dict(size=10)))
241
  print("Layout updated ")
242
+ fig.write_image(r"/code/static/images/dailybooking_lineplot.png", engine='kaleido',format='png', height=400, width = 600)
243
  # resize the image to fit in the cell - plot_bgcolor = "rgba(211, 245, 244,0.5)",
244
  print("image written")
245
+ im = Image.open('/code/static/images/dailybooking_lineplot.png')
246
  width, height = im.size
247
  im1 = im.crop((50, 75, 570, 390)) #set the crop coordinates (x,y, x+width, y+height)
248
+ im1.save('/code/static/images/dailybooking_lineplot.png')
249
  bookingstats = []
250
  bookingstats.append("The average number of booking per day is {perdaybooking2021} which is {percentdiff20n21:.1f}% {highorlow20n21} than 2020 {andorbut} {percentdiff21n19:.1f}% {highorlow21n19} than year 2019."\
251
  .format(perdaybooking2021= format(int(dlatest21.ActualBooking.mean()), ','),
 
289
  fig.update_layout({'plot_bgcolor': 'rgba(0, 0, 0, 0)','paper_bgcolor': 'rgba(0, 0, 0, 0)'})
290
  # fig.update_traces(textposition='inside', textinfo='percent+label')
291
  # fig.update_layout(coloraxis_showscale=False)
292
+ fig.write_image("/code/static/images/pie_statesytd.png", engine='kaleido',format='png')
293
 
294
  highstatelist = ', '.join([item for item in avgBookings_state.State[:5].values])
295
  last_char_index = highstatelist.rfind(",")
 
335
  fig.update_layout({'plot_bgcolor': 'rgba(0, 0, 0, 0)','paper_bgcolor': 'rgba(0, 0, 0, 0)'},
336
  xaxis = dict(tickmode = 'linear', tickangle = -45),
337
  legend=dict(orientation="h", yanchor="bottom", y=0.95, xanchor="right", x=1, font = dict(size=10)))
338
+ fig.write_image(r"/code/static/images/dailybookingdivision_barplot.png", engine='kaleido',format='png', height=400, width = 600)
339
 
340
  df192021['pChangein1921'] = (df192021['2021'] - df192021['2019']) * 100 / df192021['2019']
341
  df192021['pChangein2021'] = (df192021['2021'] - df192021['2020']) * 100 / df192021['2019']
 
383
  msgAlternative.attach(msgText)
384
 
385
  # We reference the image in the IMG SRC attribute by the ID we give it below
386
+ pngfileslist = glob(r'/code/static/images/*.png')
387
  for pngfile in pngfileslist:
388
  with open(pngfile, 'rb') as fp:
389
  msgImage = MIMEImage(fp.read())