|
from firebase_admin import credentials |
|
from firebase_admin import firestore |
|
import threading |
|
from firebase_admin import db |
|
|
|
import firebase_admin |
|
from datetime import datetime |
|
import time |
|
import Cleaning |
|
from collections import Counter |
|
def current_milli_time(): |
|
return round(time.time() * 1000) |
|
|
|
|
|
import Server.Classes as Classes |
|
db=firestore |
|
|
|
cred = credentials.Certificate( |
|
"text-to-emotions-firebase-adminsdk-8isbn-dffbdf01e8.json") |
|
firebase_admin.initialize_app(cred) |
|
|
|
|
|
|
|
all_reviews = db.collection("complaints") |
|
|
|
today_date = current_milli_time() |
|
documents_to_summarize = all_reviews.where("summary","==",None).where("date",'==',today_date).get() |
|
feedbacks = db.collection("feedbacks").where("feedbacks","==",False) |
|
|
|
|
|
documents=[] |
|
|
|
def get_all_document(): |
|
for doc in documents_to_summarize: |
|
document =Classes.Shakwa.from_dict(source=doc.to_dict()) |
|
documents.append(document) |
|
return documents |
|
|
|
|
|
|
|
def get_num_of_words(): |
|
for doc in documents_to_summarize: |
|
print(len(doc.complaintbody)) |
|
|
|
def shakwa_common_words(): |
|
for doc in documents_to_summarize: |
|
words_in_docs=" ".join(doc) |
|
words_in_docs = Cleaning.txt_preprocess(words_in_docs) |
|
most_common_words=Counter(words_in_docs) |
|
return dict(most_common_words) |
|
|
|
def feedback_common_words(): |
|
for feedback in feedbacks: |
|
words_in_feedback=" ".join(feedback) |
|
words_in_feedback = Cleaning.txt_preprocess(words_in_feedback) |
|
most_common_words=Counter(words_in_feedback) |
|
return dict(most_common_words) |
|
|
|
def get_most_common_places(): |
|
dic_place_count={} |
|
governorates=all_reviews.governorate |
|
for gov in governorates: |
|
if gov not in dic_place_count.keys(): |
|
dic_place_count[gov]=0 |
|
else : |
|
dic_place_count[gov]+=1 |
|
return dic_place_count |
|
|
|
|