-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
155 lines (137 loc) · 4.89 KB
/
utils.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
const { initializeApp } = require('firebase/app');
const { getDatabase, ref, set, onValue } = require('firebase/database');
const { getFirestore, doc, setDoc, collection } = require('firebase/firestore');
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: "AIzaSyBaL2m6vcPej-fI7hF7Y1T4LD2SMIwhYMg",
authDomain: "pln-reksti.firebaseapp.com",
databaseURL: "https://pln-reksti-default-rtdb.asia-southeast1.firebasedatabase.app",
projectId: "pln-reksti",
storageBucket: "pln-reksti.appspot.com",
messagingSenderId: "340226970797",
appId: "1:340226970797:web:7d45d89e3ca51675b4e224",
measurementId: "G-QFQ08NSKT3"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
// Get a database reference to our blog
function push(timeToFailure1, timeToFailure2) {
const db = getDatabase();
const sootblower = parseInt(timeToFailure1);
const boiler = parseInt(timeToFailure2);
set(ref(db, 'next_maintenance/'), {
sootblower, boiler
});
}
async function pushFirestore1(value1, timestamp) {
const db = getFirestore(app);
const collectionRef = collection(db, 'vibrations_1_minutes');
const newDocRef = doc(collectionRef); // Automatically generate an incremental id for the new document
await setDoc(newDocRef, {
id: newDocRef.id,
vibration: value1,
timestamp: timestamp
});
}
async function pushFirestore2(value2, timestamp) {
const db = getFirestore(app);
const collectionRef = collection(db, 'vibrations_2_minutes');
const newDocRef = doc(collectionRef); // Automatically generate an incremental id for the new document
await setDoc(newDocRef, {
id: newDocRef.id,
vibration: value2,
timestamp: timestamp
});
}
async function pushReports1(value1, timestamp) {
const db = getFirestore(app);
const collectionRef = collection(db, 'reports');
const newDocRef = doc(collectionRef); // Automatically generate an incremental id for the new document
await setDoc(newDocRef, {
id: newDocRef.id,
engine: "Sootblower",
vibration: value1,
timestamp: timestamp
});
}
async function pushReports2(value2, timestamp) {
const db = getFirestore(app);
const collectionRef = collection(db, 'reports');
const newDocRef = doc(collectionRef); // Automatically generate an incremental id for the new document
await setDoc(newDocRef, {
id: newDocRef.id,
engine: "Boiler",
vibration: value2,
timestamp: timestamp
});
}
function getDateOnly(dateTimeString) {
const dateArray = dateTimeString.split(', ')[0].split('/');
const day = dateArray[0];
const month = dateArray[1];
const year = dateArray[2];
return `${day}/${month}/${year}`;
}
function getDateOnlyOh(dateTimeString) {
const dateArray = dateTimeString.split(', ')[0].split('/');
const day = parseInt(dateArray[0]) + 3;
const month = dateArray[1];
const year = dateArray[2];
return `${day}/${month}/${year}`;
}
async function pushVisMaintenance1(timestamp) {
const db = getFirestore(app);
const collectionRef = collection(db, 'maintenances');
const newDocRef = doc(collectionRef); // Automatically generate an incremental id for the new document
const date = getDateOnly(timestamp);
await setDoc(newDocRef, {
id: newDocRef.id,
component: "Sootblower",
date: date,
type: "Check-up",
status: "On request"
});
}
async function pushVisMaintenance2(timestamp) {
const db = getFirestore(app);
const collectionRef = collection(db, 'maintenances');
const newDocRef = doc(collectionRef); // Automatically generate an incremental id for the new document
const date = getDateOnly(timestamp);
await setDoc(newDocRef, {
id: newDocRef.id,
component: "Boiler",
date: date,
type: "Check-up",
status: "On request"
});
}
async function pushOhMaintenance1(timestamp) {
const db = getFirestore(app);
const collectionRef = collection(db, 'maintenances');
const newDocRef = doc(collectionRef); // Automatically generate an incremental id for the new document
const date = getDateOnlyOh(timestamp);
await setDoc(newDocRef, {
id: newDocRef.id,
component: "Sootblower",
date: date,
type: "Overhaul",
status: "On request"
});
}
async function pushOhMaintenance2(timestamp) {
const db = getFirestore(app);
const collectionRef = collection(db, 'maintenances');
const newDocRef = doc(collectionRef); // Automatically generate an incremental id for the new document
const date = getDateOnlyOh(timestamp);
await setDoc(newDocRef, {
id: newDocRef.id,
component: "Boiler",
date: date,
type: "Overhaul",
status: "On request"
});
}
module.exports = { push, pushFirestore1, pushFirestore2, pushReports1, pushReports2, pushVisMaintenance1, pushVisMaintenance2, pushOhMaintenance1, pushOhMaintenance2};