forked from emmy-rich/448_Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
955 lines (901 loc) · 33 KB
/
index.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
require("dotenv").config();
const db = require("./database.js");
const prompt = require("prompt-sync")({sigint:true});
const fetch = require("node-fetch-commonjs");
loginDriver();
//displays the different menu options for the user to choose from
function displayMainMenu() {
console.log('\n' + "====REEL COLOSET MENU====" + '\n');
let options = ['1) View Daily Outfit', '2) View Closet', '3) Add Item to Closet', '4) Remove Item from Closet', '5) View Laundry', '6) Wash Laundry', '7) View Profile', '8) Logout', '9) Clear console\n'];
for (let i = 0; i < options.length; i++) {
console.log(options[i]);
}
}
//calls the login menu function and interprets the users input
function loginDriver() {
let stop = false;
while(stop == false) {
displayLoginMenu();
//if option 1 is selected, the user is asked to input username and password
let input1 = prompt("Please select an action to perform (1, 2, or 3): ");
if(input1 == 1) {
let username = prompt("Username: ");
let password = prompt("Password: ");
setTimeout(function(){ verify(username, password); }, 5000);//verify username after 5 seconds
stop = true;
}
//if option 2 is selected, the user is asked info to create their account
else if(input1 == 2) {
let username = prompt("Username: ");
let password = prompt("Password: ");
let email = prompt("Email: ");
if (isValidEmail(email)==false) {
console.log('\nInvalid email. Please try again.\n')
}
else {
let zipcode = prompt("Zipcode: ");
if (isValidZip(zipcode)) {
zipcode = parseInt(zipcode);
latitude(username, password, email, zipcode);
}
else {
console.log("\nInvalid zipcode. Please try again.\n");
}
}
}
//if option 3 is selected, exit the do while loop
else if(input1 == 3) {
console.log("\nThank you for using our program! Goodbye!");
stop = true;
}
else{
console.log("\nPlease enter a valid input\n");
}
}
return;
}
//main driver displays the main menu and interprets the users input
function driver(user) {
let stop = false;
let stop_out_loop = false;
displayMainMenu();
let input2 = prompt("Please select an action to perform(1-9): ");
//if option 1 is selected, user's daily outfit is generated
if(input2 == 1) {
username = user.getUsername();
user.generateOutfit(username);
stop = true;
}
//if option 2 is selected, the user's closet items are displayed
else if(input2 == 2) {
// user.getCloset();
setTimeout(function(){ user.getCloset(); }, 2000);//verify username after 5 seconds
stop = true;
}
//if option 3 is selected, the user can add an item to their closet
else if(input2 == 3) {
console.log("\nClothing Options: long_sleeve_shirt, sweater, t_shirt, tank_top, sweats, winter_skirt, jeans, skirt, jacket, coat, summer_hat, or winter_hat\n");
let art = prompt("Which article would you like to add?: ");
//checks for valid input
if(art == 'long_sleeve_shirt' || art == 'sweater'|| art== 't_shirt' || art== 'tank_top'|| art== 'sweats' || art== 'winter_skirt'|| art== 'jeans' || art== 'skirt'|| art== 'jacket'|| art== 'coat'|| art== 'summer_hat' || art =='winter_hat') {
user.add(art);
}
else {
console.log("Invalid input. Please make sure you have typed it correctly (underscores are necessary)\n");
}
}
//if option 4 is selected, the user can remove an item from their closet
else if(input2 == 4) {
console.log("Clothing Options: long_sleeve_shirt, sweater, t_shirt, tank_top, sweats, winter_skirt, jeans, skirt, jacket, coat, summer_hat, or winter_hat\n");
let art = prompt("Which article would you like to remove?: ");
//checks for valid input
if(art == 'long_sleeve_shirt' || art == 'sweater'|| art== 't_shirt' || art== 'tank_top'|| art== 'sweats' || art== 'winter_skirt'|| art== 'jeans' || art== 'skirt'|| art== 'jacket'|| art== 'coat'|| art== 'summer_hat' || art =='winter_hat') {
user.remove(art);}
else {
console.log("Invalid input please make sure you have typed it correctly (underscores are necessary)\n");
}
}
//if user selects option 5, it displays their laundry
else if(input2 == 5) {
// user.getLaundry();
setTimeout(function(){ user.getLaundry() }, 1000);//verify username after 5 seconds
}
//if user selects option 6, it cleans their laundry
else if(input2 == 6) {
user.clean();
}
//if user selects option 7, it displays their profile
else if(input2 == 7) {
console.log("\nProfile Information: ");
console.log("Username: " + user.getUsername());
console.log("Zipcode: " + user.getZipcode());
console.log("Email: " + user.getEmail());
}
//if user selects option 8, it logs the user out
else if(input2 == 8) {
console.log("\nSuccessfully logged out!\n");
loginDriver();
stop_out_loop = true;
}
//if the user selects option 9, it clears the console
else if(input2 == 9) {
console.clear();
}
//lets the user know they inputted invalid input
else {
console.log("\nPlease enter a valid input\n")
driver(user);
}
//sets a stall so everything runs at the right time and in the right order
if(input2 == 1 || input2==2 ||input2==3||input2==4||input2==5 || input2==6 ||input2==7 ||input2==9) {
setTimeout(function(){ driver(user); }, 4000);
}
stop = false;
}
//ensures that the user inputs a valid zipcode
function isValidZip(sZip) {
return /^\d{5}(-\d{4})?$/.test(sZip);
}
//ensures that the user inputs a valid email
function isValidEmail(email) {
var re = /\S+@\S+\.\S+/;
return re.test(email);
}
//displays the login or create account options to the user
function displayLoginMenu() {
displayLogo();
console.log('1) Login');
console.log('2) Create New User');
console.log('3) Quit \n');
}
//clears the console and displays the 'reelcoloset' logo to the console
function displayLogo() {
console.log(`
__
_____ ______ ______ _ _____ ____ _|__|_
| __ \\| ____| ____| | / ____/ __ \\ / _)
| |__) | |__ | |__ | | | | | | | | _/\\/\\/\\_/ /
| _ /| __| | __| | | | | | | | | _| /
| | \\ \\| |____| |____| |____ | |___| |__| | _| ( | ( |
|_| \\_\\______|______|______| \\_____\\____/ /__.-'|_|--|_| `);
console.log(`
/ _ \\/ __/ __/ / / ___/ __ \\/ / / __ \\/ __/ __/_ __/
/ , _/ _// _// /__ / /__/ /_/ / /__/ /_/ /\\ \\/ _/ / /
/_/|_/___/___/____/ \\___/\\____/____/\\____/___/___/ /_/
`);
}
//gets promise from database and passes results to login function
function verify (username, password) {
let promise = db.validateLogin(username, password)
.then((results) => {
logIn(results, username, password);
})
}
//checks if a login was sucessful
//1 = yes, 0 = no
function logIn (num, username, password) {
if (num == 1) {
console.log("\nLogin Successful!");
emailFormat(username, password);
}
else {
console.clear();
console.log("\nInvalid username or password.\n");
loginDriver();
}
}
//formats the user's email address
function emailFormat(username, password) {
let promise = db.getInfo(username, 'email')
.then((results) => {
email = results.replace('{"email":"', "");
email = email.replace('"}', "");
zipFormat(username, password, email)
})
}
//formats the user's zipcode, by turning it into an integer
function zipFormat(username, password, email) {
let promise = db.getInfo(username, 'zipcode')
.then((results) => {
zipcode = parseFloat(results.replace(/[^0-9]*/g, ''));
latFormat(username, password, email, zipcode);
})
}
//formats the user's latitude, by turning it into an integer
function latFormat(username, password, email, zipcode) {
let promise = db.getInfo(username, 'lat')
.then((results) => {
lat = parseFloat(results.replace(/[^0-9]*/g, ''));
longFormat(username, password, email, zipcode, lat);
})
}
//formats the user's longitude, by turning it into an integer
function longFormat(username, password, email, zipcode, lat) {
let promise = db.getInfo(username, 'long')
.then((results) => {
long = parseFloat(results.replace(/[^0-9]*/g, ''));
stationFormat(username, password, email, zipcode, lat, long);
})
}
//formats the user's station id
function stationFormat(username, password, email, zipcode, lat, long) {
let promise = db.getInfo(username, 'station')
.then((results) => {
station = results.replace('{"station":"', "");
station = station.replace('"}', "");
let user = new User(password, email, username, lat, long, zipcode, station);
driver(user);
})
}
//create a global variable that will be adjusted after each api call
var apiCounter =0;
//gets the latitude for a zipcode using an API
async function latitude(username, password, email, zipcode) {
const key = process.env['apiKey'];
let url= "https://api.geocod.io/v1.7/geocode?api_key=" +key +"&postal_code="+zipcode+"&format=simple";
await fetch(url)
.then(data => data.json())
.then(data=> {
if (apiCounter == 3)
{
console.log("\nFailed after three attempts. Closing.../n");
}
//api function calls itself if api call fails and api counter is less than 3
if ((data.lat === undefined)&&(apiCounter<3)) {
//increment apiCounter
apiCounter = apiCounter+1;
latitude(username, password, email, zipcode);
}
else {
//reset apiCounter
apiCounter = 0;
let latitude_ = (data.lat);
longitude(username, password, email, zipcode, latitude_);
}
});
}
//gets longitude for a zipcode using an API
async function longitude(username, password, email, zipcode, latitude) {
const key = process.env['apiKey'];
let url= "https://api.geocod.io/v1.7/geocode?api_key=" +key +"&postal_code="+zipcode+"&format=simple";
await fetch(url)
.then(data => data.json())
.then(data=> {
if (apiCounter == 3)
{
console.log("\nFailed after three attempts. Closing...\n");
}
//api function calls itself if api call fails and api counter is less than 3
if ((data.lng === undefined)&&(apiCounter<3)) {
//increment apiCounter
apiCounter = apiCounter+1;
longitude(username, password, email, zipcode);
}
else {
//reset apiCounter
apiCounter = 0;
let longitude_ = (data.lng);
station(username, password, email, zipcode, latitude, longitude_);
}
});
}
//gets the station of a zipcode using an API
async function station(username, password, email, zipcode, latitude, longitude){
let url = "https://api.weather.gov/points/"+latitude+"%2C"+longitude;
await fetch(url)
.then(data => data.json())
.then(data=> {
if (apiCounter == 3)
{
console.log("\nFailed after three attempts. Closing...\n");
}
//api function calls itself if api call fails and api counter is less than 3
if ((data.status >=400)&&(apiCounter<3)) {
//increment apiCounter
apiCounter = apiCounter+1;
station(username, password, email, zipcode, latitude, longitude);
}
else {
//reset apiCounter
apiCounter = 0;
let gridX = (data.properties.gridX);
let gridY = (data.properties.gridY);
let station = (data.properties.gridId);
db.addUser(username, password, email, zipcode, gridX, gridY, station);
}
});
}
//fetches the weather forecast for a specific user from the api using the longitude, latitude, and local station
async function checkWeather(username, gridX, gridY, station) {
let xGrid = gridX.toString();
let yGrid = gridY.toString();
let url = "https://api.weather.gov/gridpoints/"+station+"/"+xGrid+","+yGrid+"/forecast/hourly";
await fetch(url)
.then(data => data.json())
.then(data => {
if (apiCounter == 3)
{
console.log("\nFailed after three attempts. Closing...\n");
}
//if for some reason the api does not fully process, it instead calls itself again to try and force the api to properly load
if ((data.status >= 400)&&(apiCounter<3)) {
//increment apiCounter
apiCounter = apiCounter+1;
checkWeather(username,gridX,gridY,station);
}
//if the weather api finally returns something the program continues
else {
//reset apiCounter
apiCounter = 0;
//time frame has been agreed to be 9
let TIMEFRAME = 9;
//temerature of location array
let weather_temperature = [];
//forecast of location array
let weather_forecast = [];
//initialising added_temperature that will sum up all temperatures in the array
let added_temperature = 0;
//array of multiple windspeeds
let weather_windSpeed = [];
//initialising added_windSpeed that will sum up all temperatures in the array
let added_windSpeed = 0;
for (let i = 0; i<TIMEFRAME;i++) {
//pushing weather temperature at hour i into array at index i
weather_temperature[i] = data.properties.periods[i].temperature;
//pushing weather forecast at hour i into array at index i
weather_forecast[i] = data.properties.periods[i].shortForecast;
//pushing windspeed at hour i into array at index i
weather_windSpeed[i] = data.properties.periods[i].windSpeed;
//summing temperature every increment by the hour
added_temperature = added_temperature + weather_temperature[i];
//summing windspeed by every increment by the hour
//added_windSpeed = added_windSpeed + weather_windSpeed[i];
}
//average temperature
let average_weather = added_temperature/TIMEFRAME;
average_weather = Math.round((average_weather + Number.EPSILON)*100)/100;
console.log(`\nThe average weather is: ${average_weather}`);
//average wind speeed
for (let i =0; i<TIMEFRAME; i++)
{
//iterating to replace all windspeeds to be a string number and not have the mph at the end
weather_windSpeed[i] = weather_windSpeed[i].replace(" mph","");
}
for (let i =0; i<TIMEFRAME; i++)
{
//adding all the windspeeds together and forcing the string to act as an integer
added_windSpeed = added_windSpeed + (weather_windSpeed[i] * 1);
}
//averaging the sum of the total windSpeed
let average_windSpeed = added_windSpeed/TIMEFRAME;
//rounding to two decimal places
average_windSpeed = Math.round((average_windSpeed + Number.EPSILON)*100)/100;
console.log(`\nThe average wind speed is: ${average_windSpeed} mph`);
//bit forecast part to determine average forecast
//weather forecast
let weather_forecast_count= [];
let weather_forecast_mode = '';
let count_mostest = 0;
for (let i = 0;i< TIMEFRAME; i++) {
let count = 0;
//this for loop determines if the weather forecast that is in index i has already been counted and accounted for by the weather_forecast_count array
for(let j = 0 ;j< weather_forecast_count.length;j++) {
if (weather_forecast[i] == weather_forecast_count[j]) {
count =1;
}
}
//if the for loop above did not detect the identified forecast as a forecast that has been accounted for it goes through registration and count process
if (count != 1) {
//count mode just sums the specific forecast at index i over the entire array
let count_mode = 0;
for (let j = i ; j < TIMEFRAME;j++) {
if (weather_forecast[i] == weather_forecast[j]) {
count_mode++;
}
}
//if there is more then 0 of the index found at i it is pushed on the weather_forecast_count array for next loop of parent for loop
if (count_mode>0) {
weather_forecast_count.push(weather_forecast[i]);
}
//if there is a bigger count of another forecast initilise weather_forecast_mode with new forecast
if (count_mostest < count_mode) {
count_mostest = count_mode;
weather_forecast_mode = weather_forecast[i];
}
}
}
generateArticles(average_weather,weather_forecast_mode,average_windSpeed, username);
}
});
}
//generates clothing articles randomly based on the average weather
async function generateArticles(averageWeather, weatherForecastMode, averageWindSpeed, username) {
//sets the arrays for different types of articles one can wear in different seasons
let winter_tops = ["long_sleeve_shirt", "sweater"];
let summer_tops = ["t_shirt", "tank_top"];
let winter_bottoms = ["sweats", "winter_skirt", "jeans"];
let summer_bottoms = ["jeans", "skirt"];
let extra_layer = ["jacket", "coat"];
let summer_accessories =["summer_hat"];
let winter_accessories = ["winter_hat"];
let random_summer_accessory = "";
let random_winter_accessory = "";
let random_extra_layer = "";
//checks the forecast weather against different temperatures and selects a random item from the array for that clothing article
let random_top = "";
let random_bottom = "";
if(averageWeather <32) {
random_top = random_item(winter_tops);
random_bottom = random_item(winter_bottoms);
random_accessory = random_item(winter_accessories);
random_extra_layer = random_item(extra_layer); }
else if(averageWeather<=55) {
random_top = random_item(winter_tops);
random_bottom = random_item(winter_bottoms);
random_accessory = "";
random_extra_layer = random_item(extra_layer); }
else if(averageWeather<=75) {
random_top = random_item(summer_tops);
random_bottom = random_item(winter_bottoms);
random_accessory = "";
random_extra_layer = random_item(extra_layer); }
else if(averageWeather<=100) {
random_top = random_item(summer_tops);
random_bottom = random_item(summer_bottoms);
random_summer_accessory = random_item(summer_accessories);
random_extra_layer = ""; }
else if(averageWeather>100) {
random_top = random_item(summer_tops);
random_bottom = random_item(summer_bottoms);
random_accessory = random_item(summer_accessories);
random_extra_layer = ""; }
//makes an outfit with the items chosen
makeOutfit(averageWeather, username, random_top, random_bottom, random_accessory, random_extra_layer);
}
//creates an outfit for the user given the weather forecast and the articles generated in the generateArticles function
async function makeOutfit(averageWeather, username, random_top, random_bottom, random_accessory, random_extra_layer) {
let outfit="";
accessory_num = Math.floor(Math.random()*3);
extra_layer_num = Math.floor(Math.random()*3);
//checks if the weather is colder than 32 degrees
if(averageWeather <32) {
if(accessory_num ==0 && extra_layer_num==0) {
outfit = "a " + random_top + " and " + random_bottom;
checkOutfit(outfit, averageWeather);
outfit=toString(outfit);
db.getArticle(username, random_bottom);
db.getArticle(username, random_top);
}
else if(accessory_num>0 && extra_layer_num==0) {
outfit = "a " + random_top + " and " + random_bottom + " with " + random_accessory;
checkOutfit(outfit, averageWeather);
outfit=toString(outfit);
db.getArticle(username, random_bottom);
db.getArticle(username, random_top);
db.getArticle(username, random_accessory);
}
else if(accessory_num>0 && extra_layer_num >0) {
outfit = random_top + " and " + random_bottom + " with " + random_accessory + " and " + random_extra_layer;
checkOutfit(outfit, averageWeather);
outfit=toString(outfit);
db.getArticle(username, random_bottom);
db.getArticle(username, random_top);
db.getArticle(username, random_accessory);
db.getArticle(username, random_extra_layer);
}
else if(accessory_num==0 && extra_layer_num >0) {
outfit = random_top + " and " + random_bottom + " with " + random_extra_layer;
checkOutfit(outfit, averageWeather);
outfit=toString(outfit);
db.getArticle(username, random_bottom);
db.getArticle(username, random_top);
db.getArticle(username, random_extra_layer);
}
}
//assigns outfit when average temp is 55 and under
else if(averageWeather<=55) {
if(extra_layer_num==0) {
outfit = "a " + random_top + " and " + random_bottom;
checkOutfit(outfit, averageWeather);
outfit=toString(outfit);
db.getArticle(username, random_bottom);
db.getArticle(username, random_top);
}
else if (extra_layer_num>0) {
outfit = "a " + random_top + " and " + random_bottom + " with " + random_extra_layer;
checkOutfit(outfit, averageWeather);
outfit=toString(outfit);
db.getArticle(username, random_bottom);
db.getArticle(username, random_top);
db.getArticle(username, random_extra_layer);
}
}
//assigns outfit if average temp is 75 and under
else if(averageWeather<=75) {
outfit = "a " + random_top + " and " + random_bottom;
checkOutfit(outfit, averageWeather);
outfit=toString(outfit);
db.getArticle(username, random_bottom);
db.getArticle(username, random_top);
}
//assigns outfit if average temp is 100 or under
else if(averageWeather<=100) {
if(accessory_num == 0) {
outfit = "a " + random_top + " and " + random_bottom;
checkOutfit(outfit, averageWeather);
outfit=toString(outfit);
db.getArticle(username, random_bottom);
db.getArticle(username, random_top);
}
else if(accessory_num > 0) {
outfit = "a " + random_top + " and " + random_bottom + " with " + random_accessory;}
checkOutfit(outfit, averageWeather);
outfit=toString(outfit);
db.getArticle(username, random_bottom);
db.getArticle(username, random_top);
db.getArticle(username, random_accessory);
}
//assigns outfit if average temp is over 100
else if(averageWeather>100) {
if(accessory_num == 0) {
outfit = random_top + " and " + random_bottom;
checkOutfit(outfit, averageWeather);
outfit=toString(outfit);
db.getArticle(username, random_bottom);
db.getArticle(username, random_top);
}
else if(accessory_num > 0) {
outfit = random_top + " and " + random_bottom + " with " + random_accessory;
checkOutfit(outfit, averageWeather);
outfit=toString(outfit);
db.getArticle(username, random_bottom);
db.getArticle(username, random_top);
db.getArticle(username, random_accessory);
}
}
//this will delay 4 seconds and then runs willWear
setTimeout(function() { willWear(outfit, username, random_top, random_bottom, random_extra_layer, random_accessory); }, 2000);
}
//formats the outfit for readability for the user and calls function to print art
function checkOutfit(outfit, averageWeather, username) {
let outfit_spaces = "";
outfit_spaces = outfit.replaceAll("_", " ");
console.log("\nBased on an average daily temperature of " + averageWeather + " degrees Farenheight, you should wear: " + outfit_spaces + '\n');
printClothesArt(outfit, username);
}
//asks the useprompts the user, asking if they will wear the generated
//outfit or not. if yes, articles in outfit get added
function willWear(outfit, username, random_top, random_bottom, random_extra_layer, random_accessory) {
let willUserWear = prompt('Will you wear this outfit? (yes or no)');
willUserWear = willUserWear.toLowerCase();
if (willUserWear == 'yes' || willUserWear == 'y') {
db.wear(random_bottom, username);
db.wear(random_top, username);
if (random_extra_layer != "")
db.wear(random_extra_layer, username);
if(random_accessory != "")
db.wear(random_accessory, username);
// setTimeout(function() { db.wear(random_bottom, username); }, 2000);
// setTimeout(function() { db.wear(random_top, username); }, 2000);
// setTimeout(function() { db.wear(random_extra_layer, username); }, 2000);
// setTimeout(function() {db.wear(random_accessory, username); }, 2000);
}
else if (willUserWear == 'no' || willUserWear == 'n') {
// makeOutfit();
console.log("Try 1) View Daily Outfit again to get a different outfit.\n");
}
else {
console.log('Please input a valid choice, yes or no.\n');
}
}
//select a random item from an array
function random_item(arr) {
if (arr.length == 0) {
}
else {
return arr[Math.floor(Math.random()*arr.length)]
}
}
//ascii art for the clothes in the outfit
async function printClothesArt(outfit, username){
if (outfit.includes("summer_hat")) {
console.log(`
_____
.-' '-.
/ \\
|-. |
| \\ |
[__|__________|_______
`);
}
if (outfit.includes("winter_hat")) {
console.log(`
.--------.
/ '.
| .-. \\
| | '.|
|_________| /|\\
(___________) |||
`);
}
if (outfit.includes("jacket") || outfit.includes("coat")) {
console.log(`
__ __
/ \\\-// \\
/ | |. | \\
/ /| |. |\\ \\
/_/ | |. | \\_\\
|__|__|
`);
}
if (outfit.includes("long_sleeve_shirt")) {
console.log(`
__ __
/ '-' \\
/ | | \\
/ /| |\\ \\
/_/ | | \\_\\
|_____|
`);
}
if (outfit.includes("sweater")) {
console.log(`
.-//||\\\\-.
/ , , \\
/ ; ; \\
/, /| |\ .\\
\\\ \\| |/ /
\\ \\ / /
\\_/||||||\\_/
\\"===="//
`);
}
if (outfit.includes("t_shirt")) {
console.log(`
__ __
/ '-' \\
/_| |_\\
| |
| |
|_____|
`);
}
if (outfit.includes("tank_top")) {
console.log(`
__ __
| '-' |
| |
| |
| |
|_____|
`);
}
if (outfit.includes("jeans") || outfit.includes("sweats")) {
console.log(`
,==c==,
|_/|\\_|
| | |
| | |
| | |
|__|__|
`);
}
if (outfit.includes("winter_skirt")) {
console.log(`
=+===
/ |. \\
| |. |
| |. |
| |. |
| |. |
| |. |
|_/_\\___|
`);}
else if (outfit.includes("skirt")) {
console.log(`
=+===
/ |. \\
| |. |
| |. |
| |. |
|_/_\\___|
`);
}
console.log("\nCheck to see if the outfit is in your closet. If it's not, generate a new outfit, do your laundry, or wear day-old clothes and be stinky.\n Here's how many you have of each article in the outfit: ");
}
//class to represent an article of clothing
//type is a string that represents what type of clothing item it is (e.g. shirt, pants...)
//season is a string that represents when one would wear this article(e.g. summer, fall..)
class Article {
//constructor that sets the type and season to the inputted values
constructor(type, season) {
this.type = type;
this.season = season;
}
//returns type of article
getType() {
return type;
}
//returns the season of the article
getSeason() {
return season;
}
//sets the type to the new inputted type
setType(type) {
this.type = type;
}
//sets the season to the new inputted season
setSeason(season) {
this.season = season;
}
}
//class to represent and store the weather of a current place
//rain and snow are booleans represeting if it is raining/snowing
//temperature, windspeed, and humidity are int's
class Weather {
//constructor that sets the temperature, windSpeed, humidity, rain, and snow to the inputted values
constructor(temperature, windSpeed, humidity, rain, snow) {
this.temperature = temperature;
this.windSpeed = windSpeed;
this.humidity = humidity;
this.rain = rain;
this.snow = snow;
}
//return temprature value
getTemperature() {
return temperature;
}
//return wind speed value
getWindSpeed() {
return windSpeed;
}
//return humidity value
getHumidity() {
return humidity;
}
//return rain boolean
getRain() {
return rain;
}
//return snow boolean
getSnow() {
return snow;
}
//set temperature to inputted value
setTemperature(temperature) {
this.temperature = temperature
}
//set wind speed to inputted value
setWindSpeed(windSpeed) {
this.windSpeed = windSpeed;
}
//set humidity to inputted value
setHumidity(humidity) {
this.humidity = humidity;
}
//set rain to inputted value
setRain(rain) {
this.rain = rain;
}
//set snow to inputted value
setSnow(snow) {
this.snow = snow;
}
}
//Class to represent a user and store their personal data
//password, email, station and username are strings
//latitude, longitude, and zipcode are ints
//Closet and Laundry refer to the spaces storing article information in the database
class User {
//constructor that sets the password, email, username, latitude, longitude, zipcode, and station to the inputted values
constructor(password, email, username, lat, long, zipcode, station) {
this.password = password;
this.email = email;
this.username = username;
this.lat = lat;
this.long = long;
this.zipcode = zipcode;
this.station = station;
}
//increment laundry's value of that article by 1, decrement closet's value for that article by 1
wear(article) {
db.wear(article, this.username);
}
//all laundry values set to 0, closet increment by amount that was in laundry, do this for each type of article
clean() {
const clothes = ['long_sleeve_shirt','sweater','jacket','jeans','coat','tank_top', 'sweats', 'summer_hat','t_shirt','skirt', 'winter_hat', 'winter_skirt'];
for(let i = 0; i < clothes.length; i++)
{db.clean(clothes[i], this.username);}
}
//will generate an outfit to recommend based on what is in their closet and what the weather is
generateOutfit(username) {
username = this.username;
checkWeather(username, this.lat, this.long, this.station);
}
//return password value
getPassword() {
return password;
}
//return email value
getEmail() {
return email;
}
//username value
getUsername() {
return this.username;
}
//return longitude value
getLongitude() {
return longitude;
}
//return latitude value
getLatitude() {
return latitude;
}
//return zipocode value
getZipcode() {
return zipcode;
}
//return staion value
getStation() {
return station;
}
//return status of closet from database
getCloset() {
db.getCloset(this.username);
}
//return status of laundry from database
getLaundry() {
db.getLaundry(this.username);
}
//increment inputted article's value in the closet for that user by 1
add(article) {
db.add(article, this.username);
}
//decrement inputted article's value in the closet for that user by 1
remove(article) {
db.remove(article, this.username);
}
//set password to inputted value
setPassword(password) {
this.password = password;
}
//set email to inputted value
setEmail(email) {
this.email = email;
}
//set username to inputted value
setUsername(username) {
this.username = username;
}
//set latitude to inputted value
setLatitude(latitude) {
this.latitude = latitude;
}
//set longitude to inputted value
setLongitude(longitude) {
this.longitude = longitude;
}
//set zipcode to inputted value
setZipcode(zipcode) {
this.zipcode = zipcode;
}
//set station to inputted value
setStation(station) {
this.station = station;
}
}
//Class to handle user interactions
class RCServer {
//empty constructor
constructor() {
}
//check if inputted user name and password match stored username and password
validateLogin(inputUser, inputPassword) {
verify(inputUser, inputPassword);
}
//adds a new user with their inputted data
addUser(username, password, email, zipcode) {
latitude(username, password, email, zipcode);
}
}