Spaces:
Running
Running
File size: 2,094 Bytes
6954bf4 428a607 6954bf4 428a607 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import arrow
from firebase_config import firebase_db
from firebase_admin import firestore
class History:
def __init__(self, id=None, abstrak=None, kata_kunci=None, probabilitas=None, kelompok_bidang_keahlian=None, tanggal_inferensi=None, top_similarity=None):
self.id = id
self.abstrak = abstrak
self.kata_kunci = kata_kunci
self.probabilitas = probabilitas
self.kelompok_bidang_keahlian = kelompok_bidang_keahlian
self.tanggal_inferensi = tanggal_inferensi
self.top_similarity = top_similarity
def save(self, id):
_, doc = firebase_db.collection('users').document(id).collection('histories').add({
'abstrak': self.abstrak,
'kata_kunci': self.kata_kunci,
'probabilitas': self.probabilitas,
'kelompok_bidang_keahlian': self.kelompok_bidang_keahlian,
'tanggal_inferensi': self.tanggal_inferensi,
'top_similarity': self.top_similarity
})
self.id = doc.id
return self
def delete(self, id):
firebase_db.collection('users').document(id).collection('histories').document(self.id).delete()
return self
@staticmethod
def fetch(id):
histories = firebase_db.collection('users').document(id).collection('histories').order_by("tanggal_inferensi", direction=firestore.Query.DESCENDING).stream()
datas = []
for history in histories:
data = history.to_dict()
datas.append({
'id': history.id,
'abstrak': data['abstrak'],
'kata_kunci': data['kata_kunci'],
'probabilitas': dict(sorted(data['probabilitas'].items(), key=lambda item: item[1], reverse=True)),
'kelompok_bidang_keahlian': data['kelompok_bidang_keahlian'],
'tanggal_inferensi': arrow.get(data['tanggal_inferensi']).to('Asia/Jakarta').format('dddd, DD-MM-YYYY HH:mm:ss', locale='id_ID'),
'top_similarity': data['top_similarity']
})
return datas |