def gen_report(uid,field_address,field_lat,field_long,imagedate,fieldid,field_area,lang): from docx import Document from docx.shared import Inches from docx.enum.text import WD_ALIGN_PARAGRAPH from create_bargraph import create_bargraph from create_linegraph import create_linegraph import firebase_admin from firebase_admin import credentials from firebase_admin import db from firebase_admin import messaging import time import datetime from get_weather_data import get_weather_data from datetime import date from docx.shared import Pt from create_temperature_bargraph import create_temperature_bargraph from create_weather_line_graph import create_weather_line_graph import cv2 from PIL import Image from create_index_piechart import create_index_piechart from get_weather_forecast import get_weather_forecast from column_img import column_img import csv #from docx_to_pdf import docx_to_pdf # Fetch the service account key JSON file contents cred = credentials.Certificate('servicekey.json') try: firebase_admin.initialize_app(cred, {'databaseURL': 'https://farmbase-b2f7e-31c0c.firebaseio.com/'}) except: print('fire running') lang_num = 0 all_strings = [] row_num = 0 with open('report_strings.csv') as csv_file: csv_reader = csv.reader(csv_file,delimiter=',') strings_column = [] for row in csv_reader: if row_num == 0: row_num = row_num + 1 available_langs = row for singleLang in available_langs: print(('aa'+singleLang+'aa')) print(('bb'+lang+'bb')) if lang.find(singleLang)>-1: print('lang break') break else: lang_num = lang_num+1 all_strings.append(row) print('lang num') print(lang) if lang == 'ar': lang_num = 2 else: lang_num = 0 print(lang_num) today = date.today() date_d = today.strftime('%Y%m%d') year = date_d[0:4] month = date_d[4:6] day = date_d[6:] report_date = year+'-'+month+'-'+day+' (in yyyy-mm-dd)' pageno = 1 sensed_year = imagedate[0:4] sensed_month = imagedate[4:6] sensed_day = imagedate[6:] sensed_imagedate = sensed_year+'-'+sensed_month+'-'+sensed_day+' (in yyyy-mm-dd)' sensed_day = int(sensed_day) sensed_month = int(sensed_month) print('report_date') print(report_date) print(sensed_imagedate) tci_image = uid+'/TCI.png' etci_image = uid+'/ETCI.png' ndvi_image = uid+'/ndvi.png' evi_image = uid+'/evi.png' mndvi_image = uid+'/mndvi.png' ndwi_image = uid+'/ndwi.png' mndwi_image = uid+'/mndwi.png' ndre_image = uid+'/ndre.png' mndre_image = uid+'/mndre.png' vari_image = uid+'/vari.png' soc_image = uid+'/soc.png' mvari_image= uid+'/mvari.png' ndvi_image_cmap2 = uid+'/ndvi_cmap2.png' evi_image_cmap2 = uid+'/evi_cmap2.png' ndwi_image_cmap2 = uid+'/ndwi_cmap2.png' ndre_image_cmap2 = uid+'/ndre_cmap2.png' vari_image_cmap2 = uid+'/vari_cmap2.png' vari_image_cmap2 = uid+'/soc_cmap2.png' # Initialize the app with a service account, granting admin privileges health = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Health').get() try: whitelabel = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Whitelabel').get() except: whitelabel = 'no' ndvi = health["ndvi"] evi = health["evi"] ndwi = health["ndwi"] ndre = health["ndre"] vari = health["vari"] try: soc = health["soc"] except: soc = nil if lang == 'ar': alignmentType = WD_ALIGN_PARAGRAPH.RIGHT else: alignmentType = WD_ALIGN_PARAGRAPH.LEFT document = Document() font = document.styles['Normal'].font font.name = 'Calibri' header_img_url = 'APIOrganizations/'+uid + '.jpeg' try: header_img = document.add_picture(header_img_url,width=Inches(7.5)) except: try: header_img_url = 'APIOrganizations/'+whitelabel + '.jpg' header_img = document.add_picture(header_img_url,width=Inches(7.5)) except: header_img = document.add_picture('doc_header.png',width=Inches(7.5)) document.add_heading('Field Report',0) sections = document.sections for s in sections: s.top_margin=Inches(1.0) s.bottom_margin = Inches(0.5) s.left_margin = Inches(0.5) s.right_margin = Inches(0.5) section = document.sections[0] footer = section.footer para = footer.paragraphs[0] # para.text = "The data in this report is generated by Farmonaut Technologies Private Limited (farmonaut.com). Contact us at support@farmonaut.com for more information." # para.style = document.styles["Footer"] p = document.add_paragraph(all_strings[1][lang_num]) p.paragraph_format.alignment = alignmentType p = document.add_paragraph('') p.add_run('Note: ').bold = True # p.add_run('This report is auto-generated by Farmonaut systems. If you have any queries/questions regarding this report then contact us on: support@farmonaut.com').italic = True p = document.add_paragraph('') p.add_run(all_strings[2][lang_num]).bold = True p.add_run(report_date).italic = True p.paragraph_format.alignment = alignmentType p =document.add_heading(all_strings[3][lang_num],level=1) p.paragraph_format.alignment = alignmentType p = document.add_paragraph('') p.add_run(all_strings[4][lang_num]).bold = True p.add_run(field_address).italic = True p.paragraph_format.alignment = alignmentType p.add_run(all_strings[5][lang_num]).italic = True p.paragraph_format.alignment = alignmentType p = document.add_paragraph('') p.add_run(all_strings[6][lang_num]).bold = True p.paragraph_format.alignment = alignmentType p.add_run(str(field_area)).italic = True p.add_run(all_strings[7][lang_num]).italic = True p.paragraph_format.alignment = alignmentType p = document.add_paragraph('') f_lat = str(field_lat) f_lat = f_lat[0:6] f_long = str(field_long) f_long = f_long[0:6] p.add_run(all_strings[8][lang_num]).bold = True p.paragraph_format.alignment = alignmentType p.add_run(all_strings[9][lang_num]).italic = True p.paragraph_format.alignment = alignmentType p.add_run(f_lat).italic = True p.add_run(all_strings[10][lang_num]).italic = True p.paragraph_format.alignment = alignmentType p.add_run(f_long).italic = True p = document.add_paragraph('') p.add_run(all_strings[11][lang_num]).bold = True p.paragraph_format.alignment = alignmentType p.add_run(sensed_imagedate).italic = True cur_date = imagedate cur_weather_data = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Weather').child(cur_date).get() try: min_temp = cur_weather_data["min_temp"] except: min_temp = None #min_temp = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Weather').child(cur_date).child('min_temp').get() if min_temp is None: print('Weather data not available') p = document.add_paragraph('') p.add_run(all_strings[12][lang_num]).bold = True p.paragraph_format.alignment = alignmentType else: min_temp = float(min_temp)-273 min_temp = str(min_temp) min_temp = min_temp[0:5] max_temp = cur_weather_data["max_temp"] #max_temp = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Weather').child(cur_date).child('max_temp').get() max_temp = float(max_temp)-273 max_temp = str(max_temp) max_temp = max_temp[0:5] humidity = cur_weather_data["humidity"] #humidity = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Weather').child(cur_date).child('humidity').get() pressure = cur_weather_data["pressure"] #pressure = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Weather').child(cur_date).child('pressure').get() station = cur_weather_data["station"] #station = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Weather').child(cur_date).child('station').get() wind_speed = cur_weather_data["wind_speed"] #wind_speed = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Weather').child(cur_date).child('wind_speed').get() try: wind_deg = cur_weather_data["wind_deg"] except: wind_deg = 'Not Available' #wind_deg = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Weather').child(cur_date).child('wind_deg').get() try: cloud_cover = cur_weather_data["cloud_cover"] except: cloud_cover = 'Not Available' #cloud_cover = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Weather').child(cur_date).child('cloud_cover').get() p =document.add_heading(all_strings[13][lang_num]) p.paragraph_format.alignment = alignmentType p = document.add_paragraph('') p.add_run(all_strings[14][lang_num]).bold = True p.paragraph_format.alignment = alignmentType p.add_run(station).italic = True p.paragraph_format.alignment = alignmentType p = document.add_paragraph('') p.add_run(all_strings[15][lang_num]).bold = True p.add_run(min_temp).italic = True p.paragraph_format.alignment = alignmentType p = document.add_paragraph('') p.add_run(all_strings[16][lang_num]).bold = True p.paragraph_format.alignment = alignmentType p.add_run(max_temp).italic = True p.paragraph_format.alignment = alignmentType p = document.add_paragraph('') p.add_run(all_strings[17][lang_num]).bold = True p.paragraph_format.alignment = alignmentType p.add_run(str(pressure)).italic = True p.paragraph_format.alignment = alignmentType p = document.add_paragraph('') p.add_run(all_strings[18][lang_num]).bold = True p.paragraph_format.alignment = alignmentType p.add_run(str(humidity)).italic = True p.paragraph_format.alignment = alignmentType p = document.add_paragraph('') p.add_run(all_strings[19][lang_num]).bold = True p.paragraph_format.alignment = alignmentType p.add_run(str(wind_speed)).italic = True p = document.add_paragraph('') p.add_run(all_strings[20][lang_num]).bold = True p.add_run(str(wind_deg)).italic = True p.paragraph_format.alignment = alignmentType p = document.add_paragraph('') p.add_run(all_strings[21][lang_num]).bold = True p.add_run(str(cloud_cover)).italic = True p.paragraph_format.alignment = alignmentType #document.add_page_break() weather_data = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Weather').get() if weather_data is None: print('weather data not available yet') else: cloud_array = [] humidity_array = [] max_temp_array = [] min_temp_array = [] pressure_array = [] wind_deg_array = [] wind_speed_array = [] dates_array = [] for (key,val) in weather_data.items(): weather_date = key date_data = weather_data[weather_date] dates_array.append(weather_date) dates_array.sort() for key in dates_array: weather_date = key date_data = weather_data[weather_date] try: cloud_array.append(date_data["cloud_cover"]) except: cloud_array.append('not availabe') try: humidity_array.append(date_data["humidity"]) except: humidity_array.append('not available') try: t_max_temp = date_data["max_temp"]-273 except: t_max_temp = 'not available' try: t_min_temp = date_data["min_temp"]-273 except: t_min_temp = 'not available' max_temp_array.append(t_max_temp) min_temp_array.append(t_min_temp) try: pressure_array.append(date_data["pressure"]) except: pressure_array.append('not available') try: wind_deg_array.append(date_data["wind_deg"]) except: wind_deg_array.append('not available') try: wind_speed_array.append(date_data["wind_speed"]) except: wind_speed_array.append('not available') if len(dates_array)>1: try: line_types = ['min_temp','max_temp','cloud_cover','humidity','pressure','wind_speed'] weather_array = [min_temp_array,max_temp_array,cloud_array,humidity_array,pressure_array,wind_speed_array] create_weather_line_graph(uid,line_types,weather_array,dates_array) p =document.add_heading(all_strings[22][lang_num]) p.paragraph_format.alignment = alignmentType file_name = uid+'_weather_linegraph.png' document.add_picture(file_name,width=Inches(7)) except: wwq2 = 1 p =document.add_heading(all_strings[23][lang_num]) p.paragraph_format.alignment = alignmentType all_weather_data = get_weather_forecast(field_lat,field_long) all_days = [] for (key,val) in all_weather_data.items(): all_days.append(key) all_days.sort() all_days = all_days[1:] for key in all_days: #print('kk') #print(key) single_w_data = all_weather_data[key] w_date = datetime.datetime.fromtimestamp(int(key)) p=document.add_heading(str(w_date)[0:10],level=2) p.paragraph_format.alignment = alignmentType p = document.add_paragraph('') p.add_run(single_w_data["summary"]).bold = True p.paragraph_format.alignment = alignmentType p.add_run(all_strings[24][lang_num]).italic = True p.add_run(str(int(float(single_w_data["cloudcover"])*100))).italic = True p = document.add_paragraph('') p.add_run(all_strings[25][lang_num]).bold = True p.paragraph_format.alignment = alignmentType try: p.add_run(str(round(((float(single_w_data["templow"])-32)*(5/9)),2))).italic = True p.add_run((' at '+str(datetime.datetime.fromtimestamp(int(single_w_data["templowtime"])))[11:16])).italic = True p.add_run(all_strings[26][lang_num]).bold = True p.add_run(str(round(((float(single_w_data["temphigh"])-32)*(5/9)),2))).italic = True p.add_run((' at '+str(datetime.datetime.fromtimestamp(int(single_w_data["temphightime"])))[11:16])).italic = True except: print('no') p = document.add_paragraph('') if float(single_w_data["preciprob"])*100 > 50: p =document.add_heading(all_strings[27][lang_num],level=0) p.paragraph_format.alignment = alignmentType try: p.add_run(all_strings[28][lang_num]).bold = True p.paragraph_format.alignment = alignmentType p.add_run(str(round((float(single_w_data["preciprob"])*100),2))).italic = True p.add_run(all_strings[29][lang_num]).bold = True p.add_run(str((single_w_data["precimax"]))).italic = True p.add_run((' at '+str(datetime.datetime.fromtimestamp(int(single_w_data["precimaxtime"])))[11:16])).italic = True except: rrain = 0 #document.add_page_break() p =document.add_heading(all_strings[30][lang_num],level=1) p.paragraph_format.alignment = alignmentType cur_ndvi = float(ndvi[imagedate])/100 cur_ndwi = float(ndwi[imagedate])/100 cur_ndre = float(ndre[imagedate])/100 cur_vari = float(vari[imagedate])/100 cur_evi = float(evi[imagedate])/100 current_index_records = ((cur_ndvi,cur_ndwi,cur_ndre,cur_vari,cur_evi)) table = document.add_table(rows=1,cols=5) table.style = 'TableGrid' hdr_cells = table.rows[0].cells hdr_cells[0].text = 'NDVI' hdr_cells[1].text = 'NDWI' hdr_cells[2].text = 'NDRE' hdr_cells[3].text = 'VARI' hdr_cells[4].text = 'EVI' row_cells = table.add_row().cells row_cells[0].text = str(cur_ndvi) row_cells[1].text = str(cur_ndwi) row_cells[2].text = str(cur_ndre) row_cells[3].text = str(cur_vari) row_cells[4].text = str(cur_evi) document.add_paragraph('') if cur_ndvi <0.3 or cur_evi<0.3: p =document.add_heading(all_strings[31][lang_num],level=0) p.paragraph_format.alignment = alignmentType p = document.add_paragraph('') p.add_run(all_strings[32][lang_num]).bold = True p.paragraph_format.alignment = alignmentType elif (cur_ndvi>=0.3 and cur_ndvi<0.55) or (cur_evi>=0.3 and cur_evi<0.55): p =document.add_heading(all_strings[33][lang_num],level=0) p.paragraph_format.alignment = alignmentType p = document.add_paragraph('') p.add_run(all_strings[34][lang_num]).bold = True p.paragraph_format.alignment = alignmentType else: p =document.add_heading(all_strings[35][lang_num],level=0) p.paragraph_format.alignment = alignmentType p = document.add_paragraph('') p.add_run(all_strings[36][lang_num]).bold = True p.paragraph_format.alignment = alignmentType if cur_ndwi <0.3: p =document.add_heading(all_strings[37][lang_num],level=0) p.paragraph_format.alignment = alignmentType p = document.add_paragraph('') p.add_run(all_strings[38][lang_num]).bold = True p.paragraph_format.alignment = alignmentType elif (cur_ndwi>=0.3 and cur_ndwi<0.4): p=document.add_heading(all_strings[39][lang_num],level=0) p.paragraph_format.alignment = alignmentType p = document.add_paragraph('') p.add_run(all_strings[40][lang_num]).bold = True p.paragraph_format.alignment = alignmentType else: p =document.add_heading(all_strings[41][lang_num],level=0) p.paragraph_format.alignment = alignmentType p = document.add_paragraph('') p.add_run(all_strings[42][lang_num]).bold = True p.paragraph_format.alignment = alignmentType p=document.add_heading(all_strings[43][lang_num],level=0) p.paragraph_format.alignment = alignmentType p.add_run(all_strings[44][lang_num]).bold = True p.paragraph_format.alignment = alignmentType p=document.add_paragraph(all_strings[45][lang_num]) p.paragraph_format.alignment = alignmentType file_name = uid+'/hybrid.png' document.add_picture(file_name,width=Inches(6)) document.add_picture('hybrid_scale_english.jpg',width=Inches(6)) p.add_run(all_strings[46][lang_num]).bold = True p.paragraph_format.alignment = alignmentType p.add_run(all_strings[47][lang_num]).bold = True p.paragraph_format.alignment = alignmentType p=document.add_paragraph(all_strings[48][lang_num]) p.paragraph_format.alignment = alignmentType column_img(uid,fieldid,'TCI','ETCI') file_name = uid+'/collage_TCI_ETCI.png' document.add_picture(file_name,width=Inches(6)) p=document.add_heading(all_strings[49][lang_num],level=2) p.paragraph_format.alignment = alignmentType p=document.add_paragraph(all_strings[50][lang_num]) p.paragraph_format.alignment = alignmentType p = document.add_paragraph('') p.add_run(all_strings[51][lang_num]).bold = True p.paragraph_format.alignment = alignmentType p=document.add_paragraph(all_strings[52][lang_num]) p.paragraph_format.alignment = alignmentType #column_img(uid,fieldid,'colormap_farmonaut','colormap2') column_img(uid,fieldid,'ndvi','ndvi_cmap2') #column_img(uid,fieldid,(uid+'_collage_ndvi_ndvi_cmap2'),(uid+'_collagecolormap_farmonautcolormap2')) file_name= uid+'/collage_ndvi_ndvi_cmap2.png' document.add_picture(file_name,width=Inches(6.5)) file_name= 'colormap_collage.png' document.add_picture(file_name,width=Inches(6.5)) #document.add_paragraph('\nPlease check this article to read more about NDVI:\n https://farmonaut.com/blogs/remote-sensing/normalized-difference-vegetation-index-ndvi/') p=document.add_heading(all_strings[53][lang_num],level=1) p.paragraph_format.alignment = alignmentType ndvi_records = ndvi dates = [] ndvi_columns = len(ndvi_records)+1 if ndvi_columns > 11: ndvi_columns = 11 table = document.add_table(rows=1,cols=ndvi_columns) table.style = 'TableGrid' hdr_cells = table.rows[0].cells i =0 t_index = 0 for (key,val) in ndvi_records.items(): dates.append(key) dates.sort() for key in dates: if i==0: hdr_cells[t_index].text = all_strings[54][lang_num] hdr_cells[t_index].bold = True i = i+1 t_index = t_index +1 y = key[0:4] m = key[4:6] d = key[6:] kk = y+'-'+m+'-'+d if len(ndvi_records) - i < 10: hdr_cells[t_index].text = kk hdr_cells[t_index].bold = True t_index = t_index + 1 i = i+1 if t_index == 11: break row_cells = table.add_row().cells i = 0 t_index = 0 for key in dates: if i==0: row_cells[t_index].text = all_strings[55][lang_num] i=i+1 t_index =t_index +1 val = float(ndvi_records[key])/100 if len(ndvi_records) - i < 10: row_cells[t_index].text = str(val) row_cells[t_index].bold = True t_index =t_index +1 i=i+1 if t_index == 11: break document.add_paragraph('') if len(ndvi_records)>1: #document.add_heading('Graph of NDVI vs Time',level=2) create_linegraph(uid,'ndvi',ndvi) column_img(uid,fieldid,'ndvi_piechart','ndvi_linegraph') file_name = uid+'/collage_ndvi_piechart_ndvi_linegraph.png' document.add_picture(file_name,width=Inches(7.5)) else: #p = document.add_paragraph('') file_name = uid+'/ndvi'+'_piechart.png' document.add_picture(file_name,width=Inches(6)) p=document.add_heading(all_strings[56][lang_num],level=2) p.paragraph_format.alignment = alignmentType p=document.add_paragraph(all_strings[57][lang_num]) p.paragraph_format.alignment = alignmentType p = document.add_paragraph('') p.add_run(all_strings[58][lang_num]).bold = True p.paragraph_format.alignment = alignmentType p=document.add_paragraph(all_strings[59][lang_num]) p.paragraph_format.alignment = alignmentType #column_img(uid,fieldid,'colormap_farmonaut','colormap2') column_img(uid,fieldid,'evi','evi_cmap2') #column_img(uid,fieldid,(uid+'_collage_ndvi_ndvi_cmap2'),(uid+'_collagecolormap_farmonautcolormap2')) file_name= uid+'/collage_evi_evi_cmap2.png' document.add_picture(file_name,width=Inches(6.5)) file_name= 'colormap_collage.png' document.add_picture(file_name,width=Inches(6.5)) p=document.add_heading(all_strings[60][lang_num],level=1) p.paragraph_format.alignment = alignmentType evi_records = evi dates = [] evi_columns = len(evi_records)+1 if evi_columns > 11: evi_columns = 11 table = document.add_table(rows=1,cols=evi_columns) table.style = 'TableGrid' hdr_cells = table.rows[0].cells i =0 t_index =0 for (key,val) in evi_records.items(): dates.append(key) dates.sort() for key in dates: if i==0: hdr_cells[t_index].text = all_strings[61][lang_num] hdr_cells[t_index].bold = True i = i+1 t_index =t_index +1 y = key[0:4] m = key[4:6] d = key[6:] kk = y+'-'+m+'-'+d if len(evi_records) - i < 10: hdr_cells[t_index].text = kk hdr_cells[t_index].bold = True t_index =t_index +1 i = i+1 # t_index =t_index +1 if t_index == 11: break row_cells = table.add_row().cells i = 0 t_index =0 for key in dates: if i==0: row_cells[t_index].text = all_strings[62][lang_num] i=i+1 t_index =t_index +1 val = float(evi_records[key])/100 if len(evi_records) - i < 10: row_cells[t_index].text = str(val) row_cells[t_index].bold = True t_index =t_index +1 i=i+1 if t_index == 11: break document.add_paragraph('') if len(evi_records)>1: #document.add_heading('Graph of NDVI vs Time',level=2) create_linegraph(uid,'evi',evi) column_img(uid,fieldid,'evi_piechart','evi_linegraph') file_name = uid+'/collage_evi_piechart_evi_linegraph.png' document.add_picture(file_name,width=Inches(7.5)) else: #p = document.add_paragraph('') file_name = uid+'/evi'+'_piechart.png' document.add_picture(file_name,width=Inches(6)) p=document.add_heading(all_strings[63][lang_num],level=2) p.paragraph_format.alignment = alignmentType p=document.add_paragraph(all_strings[64][lang_num]) p.paragraph_format.alignment = alignmentType p = document.add_paragraph('') p.add_run(all_strings[65][lang_num]).bold = True p.paragraph_format.alignment = alignmentType p=document.add_paragraph(all_strings[66][lang_num]) p.paragraph_format.alignment = alignmentType column_img(uid,fieldid,'ndre','ndre_cmap2') file_name= uid+'/collage_ndre_ndre_cmap2.png' document.add_picture(file_name,width=Inches(6.5)) file_name= 'colormap_collage.png' document.add_picture(file_name,width=Inches(6.5)) #document.add_paragraph('\nPlease check this article to understand the difference between NDVI and NDRE images and their applications in agriculture: https://farmonaut.com/blogs/remote-sensing/ndvi-vs-ndre-and-their-applications-in-agriculture/') p=document.add_heading(all_strings[67][lang_num],level=1) p.paragraph_format.alignment = alignmentType ndre_records = ndre ndre_columns = len(ndre_records)+1 if ndre_columns > 11: ndre_columns = 11 table = document.add_table(rows=1,cols=ndre_columns) table.style = 'TableGrid' hdr_cells = table.rows[0].cells dates = [] for (key,val) in ndre_records.items(): dates.append(key) dates.sort() i =0 t_index =0 for key in dates: if i==0: hdr_cells[t_index].text = all_strings[68][lang_num] hdr_cells[t_index].bold = True i = i+1 t_index = t_index +1 y = key[0:4] m = key[4:6] d = key[6:] kk = y+'-'+m+'-'+d if len(ndre_records) - i < 10: hdr_cells[t_index].text = kk hdr_cells[t_index].bold = True t_index =t_index +1 i = i+1 if t_index == 11: break row_cells = table.add_row().cells i = 0 t_index =0 for key in dates: if i==0: row_cells[t_index].text = all_strings[69][lang_num] i=i+1 t_index =t_index +1 val = float(ndre_records[key])/100 if len(ndre_records) - i < 10: row_cells[t_index].text = str(val) row_cells[t_index].bold = True t_index =t_index +1 i=i+1 if t_index == 11: break document.add_paragraph('') if len(ndre_records)>1: #document.add_heading('Graph of NDRE vs Time',level=2) create_linegraph(uid,'ndre',ndre) column_img(uid,fieldid,'ndre_piechart','ndre_linegraph') file_name = uid+'/collage_ndre_piechart_ndre_linegraph.png' document.add_picture(file_name,width=Inches(7.0)) else: #p = document.add_paragraph('') file_name = uid+'/ndre'+'_piechart.png' document.add_picture(file_name,width=Inches(6)) p=document.add_heading(all_strings[70][lang_num],level=2) p.paragraph_format.alignment = alignmentType p=document.add_paragraph(all_strings[71][lang_num]) p.paragraph_format.alignment = alignmentType p = document.add_paragraph('') p.add_run(all_strings[72][lang_num]).bold = True p.paragraph_format.alignment = alignmentType document.add_paragraph(all_strings[73][lang_num]) column_img(uid,fieldid,'ndwi','ndwi_cmap2') file_name= uid+'/collage_ndwi_ndwi_cmap2.png' document.add_picture(file_name,width=Inches(6.5)) file_name= 'colormap_collage.png' document.add_picture(file_name,width=Inches(6.5)) #document.add_paragraph('\nPlease check this article to read more about NDWI: https://farmonaut.com/blogs/remote-sensing/normalized-difference-water-index-ndwi/') document.add_paragraph('') p=document.add_heading(all_strings[74][lang_num]) p.paragraph_format.alignment = alignmentType ndwi_records = ndwi ndwi_columns = len(ndwi_records)+1 if ndwi_columns > 11: ndwi_columns = 11 table = document.add_table(rows=1,cols=ndwi_columns) table.style = 'TableGrid' hdr_cells = table.rows[0].cells dates = [] for (key,val) in ndwi_records.items(): dates.append(key) dates.sort() i =0 t_index =0 for key in dates: if i==0: hdr_cells[t_index].text = all_strings[75][lang_num] hdr_cells[t_index].bold = True i = i+1 t_index = t_index +1 y = key[0:4] m = key[4:6] d = key[6:] kk = y+'-'+m+'-'+d if len(ndwi_records) - i < 10: hdr_cells[t_index].text = kk hdr_cells[t_index].bold = True t_index =t_index +1 i = i+1 if t_index == 11: break row_cells = table.add_row().cells i = 0 t_index =0 for key in dates: if i==0: row_cells[t_index].text = all_strings[76][lang_num] i=i+1 t_index =t_index +1 val = float(ndwi_records[key])/100 if len(ndwi_records) - i < 10: row_cells[t_index].text = str(val) row_cells[t_index].bold = True t_index =t_index +1 i=i+1 if t_index == 11: break document.add_paragraph('') if len(ndwi_records)>1: #document.add_heading('Graph of NDWI vs Time',level=2) create_linegraph(uid,'ndwi',ndwi) column_img(uid,fieldid,'ndwi_piechart','ndwi_linegraph') file_name = uid+'/collage_ndwi_piechart_ndwi_linegraph.png' document.add_picture(file_name,width=Inches(7.0)) else: #p = document.add_paragraph('') file_name = uid+'/ndwi'+'_piechart.png' document.add_picture(file_name,width=Inches(6)) p=document.add_heading(all_strings[77][lang_num],level=2) p.paragraph_format.alignment = alignmentType p=document.add_paragraph(all_strings[78][lang_num]) p.paragraph_format.alignment = alignmentType file_name= uid+'/evapo.png' document.add_picture(file_name,width=Inches(6.5)) document.add_picture('evapo_scale.JPG',width=Inches(6.5)) p=document.add_heading(all_strings[79][lang_num],level=2) p.paragraph_format.alignment = alignmentType p=document.add_paragraph(all_strings[80][lang_num]) p.paragraph_format.alignment = alignmentType column_img(uid,fieldid,'soc','soc_cmap2') file_name= uid+'/collage_soc_soc_cmap2.png' document.add_picture(file_name,width=Inches(6.5)) #file_name= 'colormap_collage_vari.jpg' #document.add_picture(file_name,width=Inches(6.5)) p=document.add_heading(all_strings[81][lang_num]) p.paragraph_format.alignment = alignmentType vari_records = soc vari_columns = len(vari_records)+1 if vari_columns > 11: vari_columns = 11 table = document.add_table(rows=1,cols=vari_columns) table.style = 'TableGrid' hdr_cells = table.rows[0].cells dates = [] for (key,val) in vari_records.items(): dates.append(key) dates.sort() i =0 t_index =0 for key in dates: if i==0: hdr_cells[t_index].text = all_strings[82][lang_num] hdr_cells[t_index].bold = True i = i+1 t_index =t_index +1 y = key[0:4] m = key[4:6] d = key[6:] kk = y+'-'+m+'-'+d if len(vari_records) - i < 10: hdr_cells[t_index].text = kk hdr_cells[t_index].bold = True t_index =t_index +1 i = i+1 if t_index == 11: break row_cells = table.add_row().cells i = 0 t_index =0 print('lang num') print(lang_num) print(all_strings[82][lang_num]) for key in dates: if i==0: row_cells[t_index].text = all_strings[83][lang_num] i=i+1 t_index =t_index +1 val = float(vari_records[key]) if len(vari_records) - i < 10: row_cells[t_index].text = str(val) row_cells[t_index].bold = True t_index =t_index +1 i=i+1 if t_index == 11: break document.add_paragraph('') if len(vari_records)>1: #document.add_heading('Graph of VARI vs Time',level=2) create_linegraph(uid,'soc',vari) column_img(uid,fieldid,'soc_piechart','soc_linegraph') file_name = uid+'/collage_soc_piechart_soc_linegraph.png' document.add_picture(file_name,width=Inches(7.0)) else: #p = document.add_paragraph('') file_name = uid+'/soc'+'_piechart.png' document.add_picture(file_name,width=Inches(6)) file_name = uid+'/report.docx' document.save(file_name)