from tempfile import tempdir import firebase_admin from firebase_admin import credentials from firebase_admin import db from find_s1_image2 import find_img_value import pandas as pdf from sklearn.metrics import classification_report, confusion_matrix, accuracy_score import statsmodels.api as sm import seaborn as sns sns.set() import traceback from sklearn.ensemble import RandomForestRegressor from sklearn.model_selection import train_test_split import csv import time import json from find_modis_ndvi import find_modis_ndvi import numpy as np from sklearn.cluster import KMeans from sentinelhub import WebFeatureService, BBox, CRS, MimeType, CRS, BBox, WmsRequest,DataCollection import traceback from get_mask import get_mask from PIL import Image import numpy as np from google.cloud import storage import requests cred = credentials.Certificate('servicekey.json') x = 0.0003 y = 0.0003 fromdate = '20220701' todate = '20220715' s1_images = ['IW-VH-DB'] s2_images = [] # s1_images = ["B02", "B03", "B04", "B05"] #s2_images = ["RVI-NEW"] try: firebase_admin.initialize_app(cred, {'databaseURL': 'https://farmbase-b2f7e-31c0c.firebaseio.com/'}) except: print('fire running') #get all non_gt farms #uid = 'lnR1AGuLgmPWk5ZzEtFS3FlGRj42' # field_ids = [1679967002882, 1679966729923, 1679564467926, 1676093083960, 1676092753184, 1676092238980, 1676092127138, 1676092080769, 1675836972336, 1675836874915, 1675836770812, 1675836706947, 1675224126040, 1675223688824, 1675223584847, 1675222777316, 1675222680174, 1675220202897, 1675219711420, 1675219573442, 1675219344911] # for fieldid in field_ids: # fieldid = str(fieldid) # field_obj = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('SensedDays').delete() # time.sleep(0.1) #uid = 'qL4tgUcl1ggqLRFFgxTNbTgP3uk1' uid = 'M53J9SImW9My4vghlCaaWLYxsc22' #uid ='3slpdq65yYXR6M9zDU2I3Ng6kRD2' uid = 'sAiJIWRbNOR5grDmRabVxW5BXp03' uid = '4bsSM4efIGhVVmOUyJv8DshNxYG3' uid = 'ENLgcB9pl2fH7MjsEH7oc72YBRh2' uid = 'b0oOOCM3jFUHMy9CsL2RYENMAHC3' uid = 'cO3iCeT1cYfPpmq35RYVE9nWTFz1' uid = 'hbPx8Vep5OTxnouajuHKkg0PXvw2' uid = 'XSzwRsmzu4OeCm8UvllGn7xsnOk1' kisanwala_obj = db.reference('PaidMonitoredFields').child('PMF').child(uid).get() current_field_ids = [] total_units = 0 for (fieldid, fieldObj) in kisanwala_obj.items(): try: # fieldid = str(fieldid) db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Expired').delete() db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Expiring').delete() db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Paused').set('no') db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('PaymentType').set('8') # fd = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('SensedDays').get() # area_sq = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('FieldArea').get() # area_ha = round(int(area_sq)/10000) # if area_ha < 1: # area_ha = 1 # day_count = 0 # for(p,q) in fd.items(): # day_count = day_count+1 # n_months = round(day_count/6) # if n_months < 1: # n_months = 1 # this_units = n_months*area_ha*6 # print([n_months, area_ha, this_units]) # total_units = total_units + this_units # orgData = fieldObj["OrgData"] # villageName = orgData["OrgVillageName"] # if villageName != "LONI" and villageName != "ANJHI ADAMPUR": # fd = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('SensedDays').get() # days_arr = [] # for(p,q) in fd.items(): # days_arr.append(int(p)) # max_d = str(max(days_arr)) # db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('SensedDays').child(max_d).delete() # print(max_d) except: print(traceback.format_exc()) #db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('FieldAddress').set(fd) # try: # coordinates = fieldObj["Coordinates"] # temp_obj = {} # temp_obj["UID"] = uid # temp_obj["Points"] = coordinates # r = requests.post('https://us-central1-farmbase-b2f7e.cloudfunctions.net/getFieldAreaByBoundaryPoints', json = temp_obj) # t_obj = r.text # new_obj = json.loads(t_obj) # new_area = str(new_obj["FieldArea"]) # print(new_area) # db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child("FieldArea").set(new_area) # time.sleep(0.1) # except: # print(traceback.format_exc())