import pandas as pd from collections import defaultdict from itertools import zip_longest from tempfile import tempdir import firebase_admin from firebase_admin import credentials from firebase_admin import db from find_s1_image import find_img_value import pandas as pd from sklearn.metrics import classification_report, confusion_matrix, accuracy_score import statsmodels.api as sm import seaborn as sns sns.set() from zipfile import ZipFile 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 find_study_area_values import find_study_area_values from find_study_area_values3 import find_study_area_values3 from make_area_estimate_image import make_area_estimate_image from make_egypt_estimate_image import make_egypt_estimate_image from sentinelhub import WebFeatureService, BBox, CRS, MimeType, CRS, BBox, WmsRequest,DataCollection import traceback from firebase_admin import firestore from PIL import Image import numpy as np from google.cloud import storage import os from firebase_admin import db from get_mask import get_mask import cv2 import scipy.ndimage from google.oauth2 import service_account import datetime from datetime import date from get_polygon_mask import get_polygon_mask import requests import traceback from ftplib import FTP import paramiko import pysftp import math storage_client = storage.Client.from_service_account_json("servicekey.json"); bucket_name = 'farmbase-b2f7e.appspot.com' cred = service_account.Credentials.from_service_account_file('servicekey.json') #cred = credentials.Certificate('servicekey.json') bucket = storage_client.bucket(bucket_name) try: firebase_admin.initialize_app(credentials.Certificate('servicekey.json'), {'databaseURL': 'https://farmbase-b2f7e-31c0c.firebaseio.com/'}) except: print('fire running') cost_per_obj = 0.2 total_cost = 0 total_area = 0 timestamp = 1704047400000 whitelabel_obj = db.reference("Whitelabel").child("sat_fashionforbiodiversity_com").get() for (uid, fields_obj) in whitelabel_obj.items(): print(uid) fields_obj = db.reference("PaidMonitoredFields").child("PMF").child(uid).get() if fields_obj is not None: for (fieldid, field_obj) in fields_obj.items(): if int(fieldid) > int(timestamp): fieldid = str(fieldid) field_area = field_obj.get("FieldArea",0) if field_area < int(10000): field_area = 10000 payment_type = round(float(field_obj.get("PaymentType",0)),2) if field_area == 0: deleted_sensed_obj = db.reference("DeletedFields").child("PMF").child(uid).child(fieldid).child("SensedDays").get() if deleted_sensed_obj is not None: sensed_num = 0 for (sensed_day, val) in deleted_sensed_obj.items(): sensed_num = sensed_num + 1 payment_type = round((sensed_num/6),2) #print(payment_type) farm_cost = round((float(field_area/10000)*float(payment_type)*cost_per_obj),2) total_cost = total_cost + farm_cost total_area = total_area + field_area email = field_obj.get("Email",None) if email is not None: str_txt = "Email ID: " + str(email) + ", Field ID: " + str(fieldid) + ", Field Area: " + str(round(float(field_area/10000),2)) +" Ha, Payment Type: " + str(payment_type) + " Months, Cost: $" + str(farm_cost) #print(fieldid, uid, field_area, total_area,payment_type, farm_cost, total_cost) print(str_txt) fields_obj = db.reference("DeletedFields").child("PMF").child(uid).get() if fields_obj is not None: for (fieldid, field_obj) in fields_obj.items(): if int(fieldid) > int(timestamp): fieldid = str(fieldid) field_area = field_obj.get("FieldArea",0) if field_area < int(10000): field_area = 10000 payment_type = round(float(field_obj.get("PaymentType",0)),2) farm_cost = round((float(field_area/10000)*float(payment_type)*cost_per_obj),2) total_cost = total_cost + farm_cost total_area = total_area + field_area email = field_obj.get("Email",None) if email is not None: str_txt = "Email ID: " + str(email) + ", Field ID: " + str(fieldid) + ", Field Area: " + str(round(float(field_area/10000),2)) +" Ha, Payment Type: " + str(payment_type) + " Months, Cost: $" + str(farm_cost) #print(fieldid, uid, field_area, total_area,payment_type, farm_cost, total_cost) print(str_txt) print(total_cost)