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 from simplify_coordinates import simplify_coordinates 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') uid = 'TCXcp5VIsfhHZrh0nm2VsgBtcGy2' uid = 'ipRHhCOFIDV2pxgg7Nfz1ufZBmV2' num = 0 main_num = 0 #test_uid = 'MtO6G7AvlnPgQxAajMP6NtLS8fN2' temp_list = db.reference('PaidMonitoredFields').child('PMF').child(uid).get(False, True) uid_list = {} for rr, tt in temp_list.items(): #get all polygons in the field # if int(rr) < 1714847400000: # db.reference('PaidMonitoredFields').child('PMF').child(uid).child(rr).delete() # print(rr) # time.sleep(0.1) polygons_obj = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(rr).child('Polygons').get(False, True) try: for polygon_id, uu in polygons_obj.items(): polygon_id = str(polygon_id) sensed_days_obj = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(rr).child('Polygons').child(polygon_id).child('SensedDays').get() sensed_days_arr = [] try: for temp_key, val in sensed_days_obj.items(): sensed_days_arr.append(int(temp_key)) if len(sensed_days_arr) >0: if max(sensed_days_arr) > 20240410: main_num = main_num + 1 print(main_num) except: print(traceback.format_exc()) # main_num = main_num + 1 # #check if the polygon exists in the polygons tree # paid_polygon_id = db.reference('PaidPolygonsByPolygonID').child('PMF').child(uid).child(polygon_id).child('polygonID').get() # #print((polygon_id,paid_polygon_id)) # if paid_polygon_id is None: # num = num+1 # #print(num) # actual_polygon_obj = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(rr).child('Polygons').child(polygon_id).get() # db.reference('PaidPolygonsByPolygonID').child('PMF').child(uid).child(polygon_id).set(actual_polygon_obj) except: print(traceback.format_exc()) print((main_num, num))