Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Commit

Permalink
Merge branches 'master' and 'segni.admin' of https://github.com/emrev…
Browse files Browse the repository at this point in the history
…arol/A2SV into segni.admin

� Conflicts:
�	covid-19-app-web/src/components/core/DateRangePicker.vue
�	covid-19-app-web/src/router/admin.js
  • Loading branch information
TripleThreads committed Aug 26, 2020
2 parents b0c3106 + 214021c commit 69cc808
Show file tree
Hide file tree
Showing 97 changed files with 3,138 additions and 351 deletions.
14 changes: 12 additions & 2 deletions Backend/controllers/SymptomStatisticsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,18 @@ exports.get_symptom_logs = async (req, res) => {
filter["current_symptoms.location.district"] = {$in : districts};
}

if(req.query.date){
filter["current_symptoms.date"] = {$lte : new Date(req.query.date)}
if(req.query.start_date){
filter["current_symptoms.date"] = {$gte : new Date(req.query.start_date)}
}else{
let date = new Date()
date.setHours(date.getHours()-24)
filter["current_symptoms.date"] = {$gte : date}
}

if(req.query.end_date){
let date = new Date(req.query.end_date)
date.setHours(23)
Object.assign(filter["current_symptoms.date"], {$lte : date});
}

let page = parseInt(req.query.page) || 1;
Expand Down
16 changes: 8 additions & 8 deletions Backend/controllers/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,14 @@ exports.send_invitation_link = async (req, res) => {
exports.send_multiple_invitation_link = async (req, res) => {
let emails = req.body.emails;
try {
User.find({ email: { $in: emails }}, (err, results) => {
const existingEmails = results.map(user => user.email);
if (existingEmails.length > 0) {
return res
.status(422)
.send( { "error": "This emails already exist.", "emails" :existingEmails });
}
});
let existingEmails= await User.find({ email: { $in: emails }});

existingEmails = existingEmails.map(user => user.email);
if (existingEmails.length > 0) {
return res
.status(422)
.send( { "error": "This emails already exist.", "emails" :existingEmails });
}

if (emails==undefined){
return res
Expand Down
66 changes: 32 additions & 34 deletions Backend/services/UpdateTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,43 +453,41 @@ exports.update_public_resources = async () => {

//Every 4 hours
exports.update_world_statistics = async () => {
let request_url =
"https://datahub.io/core/covid-19/r/worldwide-aggregated.csv";
let wldData = await axios.get(request_url);

let data = wldData.data;
if (data) {
const options = { delimiter: ",", quote: '"' };
data = csvjson.toObject(data, options);
let caseData = [];
console.log(data.length);
for (var index = 0; index < data.length; index++) {
let item = data[index];

caseData.push(
new WorldDataModel({
_id: mongoose.Types.ObjectId(),
Confirmed: item["Confirmed"],
Recovered: item["Recovered"],
Deaths: item["Deaths"],
date: new Date(item.Date),
})
);
}
if (caseData.length > 0) {
try {
await WorldDataModel.collection.drop();
} catch (err) {
console.log(err.toString());
}
try {
await WorldDataModel.insertMany(caseData, { ordered: false });
} catch (err) {
console.log(err.toString());
const cases = await MapData.find({});
let casesData = {};
cases.forEach((country) => {
Object.keys(country.Data).forEach((key) => {
if (key !== "Country" && key != "Unique_Provinces") {
if (!casesData[`${key}`]) {
casesData[`${key}`] = new WorldDataModel({
_id: mongoose.Types.ObjectId(),
Confirmed: 0,
Recovered: 0,
Deaths: 0,
date: new Date(key),
});
}
casesData[`${key}`].Confirmed += country.Data[`${key}`][0];
casesData[`${key}`].Recovered += country.Data[`${key}`][2];
casesData[`${key}`].Deaths += country.Data[`${key}`][1];
}
});
});
const data = Object.keys(casesData).map(function (key) {
return casesData[key];
});
if (data && data.length > 0) {
try {
await WorldDataModel.collection.drop();
} catch (err) {
console.log(err.toString());
}
try {
await WorldDataModel.insertMany(data, { ordered: false });
} catch (err) {
console.log(err.toString());
}
}

console.log("update-completed");
};

Expand Down
149 changes: 45 additions & 104 deletions Backend/test/SymptomStatisticsControllerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,96 +19,6 @@ chai.use(chaiHttp);

describe("Symptom Statistics API", function() {
describe("Statistics Tests", function(){
let user;
let user_location;
let symptom_user;
let district;
let date = new Date();
date.setHours(date.getHours() - 24);
beforeEach(async () => {
user = new User({
_id: mongoose.Types.ObjectId(),
username: `${Date.now().toString()} ${Math.random()}`,
password: "$2a$10$efmxm5o1v.inI.eStGGxgO1zHk.L6UoA9LEyYrRPhWkmTQPX8.NKO",
gender: "FEMALE",
age_group: "21-30",
current_country: "Ethiopia"
});
await user.save();

symptom_user = new SymptomUser({
_id: mongoose.Types.ObjectId(),
user_id: user._id,
symptom_id: mongoose.Types.ObjectId(),
});
await symptom_user.save();

district = new DistrictModel({
_id: mongoose.Types.ObjectId(),
name: "Bole",
state: "Addis Abeba",
boundaries: {
type: "Polygon",
coordinates: [[38.77277374267584, 8.951707839965763], [38.7750511169433, 8.959457397461051], [38.76938629150402, 8.964635848999023], [38.76857757568365, 8.971710205078125], [38.76391220092779, 8.975526809692496], [38.76419830322271, 8.980051994323787], [38.769969940185604, 8.984671592712402], [38.774642944335994, 8.990886688232422], [38.77341461181652, 8.99995040893566], [38.775791168213004, 9.005511283874455], [38.774803161621094, 9.01102256774908], [38.77674102783209, 9.015738487243652], [38.783794403076286, 9.014875411987418], [38.792392730713004, 9.01681900024414], [38.798694610595646, 9.018692970275879], [38.808036804199276, 9.019802093505973], [38.81892013549799, 9.018701553344727], [38.829669952392635, 9.021367073059196], [38.840248107910156, 9.020879745483398], [38.85087585449219, 9.020322799682617], [38.85769271850586, 9.019966125488281], [38.87712860107433, 9.021015167236328], [38.88451766967785, 9.02137374877924], [38.889778137206974, 9.022211074829158], [38.89665985107422, 9.030497550964299], [38.90116119384777, 9.019584655761719], [38.90500259399414, 9.009499549865723], [38.90605545043957, 8.997531890869084], [38.904338836670036, 8.992156982421875], [38.90489959716797, 8.984115600585938], [38.90624237060547, 8.977418899536246], [38.90409469604498, 8.969542503357047], [38.90278625488281, 8.962411880493164], [38.89623641967779, 8.954837799072266], [38.90110015869146, 8.946141242981014], [38.89675903320318, 8.937026977539062], [38.891422271728516, 8.934331893920955], [38.88208007812506, 8.936197280883903], [38.869491577148494, 8.939620018005314], [38.861419677734375, 8.94267749786377], [38.85555648803711, 8.938292503356934], [38.84938430786144, 8.938275337219238], [38.841060638427734, 8.941080093383789], [38.83596801757824, 8.942173957824764], [38.82828903198242, 8.939469337463322], [38.82053756713873, 8.937870025634766], [38.81644439697271, 8.941584587097282], [38.8088836669923, 8.944089889526424], [38.80073547363281, 8.945956230163688], [38.79402923583979, 8.942293167114315], [38.785774230957145, 8.938777923583928], [38.78005981445324, 8.935907363891602], [38.7739372253418, 8.940291404724178], [38.771129608154354, 8.94519901275629], [38.77277374267584, 8.951707839965763]]
}
})
await district.save()

user_location = new LocationUser({
user_id: user._id,
location: {
type: "Point",
coordinates: [38.796897, 8.985974],
district: district._id
},
TTL: 10000,
});
await user_location.save();
});

afterEach(async () => {
await LocationUser.findByIdAndDelete(user_location._id);
await SymptomUser.findByIdAndDelete(symptom_user._id);
await DistrictModel.findByIdAndDelete(district._id);
await User.findByIdAndDelete(user._id);
});

it("it should return total number of symptoms on /api/symptom_statistics GET", async () => {
let response = await chai
.request(server)
.get("/api/symptom_statistics")
expect(response).to.have.status(200);
expect(response.body).to.have.property("result").greaterThan(0);
});

it("it should return total number of symptoms with the given filters on /api/symptom_statistics GET", async () => {
let response = await chai
.request(server)
.get("/api/symptom_statistics")
.query({country: "Ethiopia", date: date})
expect(response).to.have.status(200);
expect(response.body).to.have.property("result").greaterThan(0);
});

it("it should return total number of symptoms with the given filters on /api/symptom_statistics GET", async () => {
let response = await chai
.request(server)
.get("/api/symptom_statistics")
.query({district: "Bole", date: date})
expect(response).to.have.status(200);
expect(response.body).to.have.property("result").greaterThan(0);
});

it("it should return total number of people with symptoms on /api/symptom_statistics/people GET", async () => {
let response = await chai
.request(server)
.get("/api/symptom_statistics/people")
expect(response).to.have.status(200);
expect(response.body).to.have.property("result").greaterThan(0);
});
});

describe("Most Common Symptoms Tests", function(){
let user;
let user_location;
let symptom_user1;
Expand Down Expand Up @@ -203,33 +113,52 @@ describe("Symptom Statistics API", function() {
await Symptom.findByIdAndDelete(symptom2._id);
});

it("it should return list of symptoms sorted by most common on /api/symptom_statistics/most_common GET", async () => {
it("it should return list of symptoms sorted by most common on /api/symptom_statistics GET", async () => {
let response = await chai
.request(server)
.get("/api/symptom_statistics/most_common")
.get("/api/symptom_statistics")
expect(response).to.have.status(200);
expect(response.body).to.be.an("array");
expect(response.body[0]).to.have.property("name", "Headaches");
expect(response.body).to.be.an("object");
expect(response.body.data).to.be.an("array");
expect(response.body).to.have.property("total");
expect(response.body.data[0]).to.have.property("count");
});

it("it should return list of symptoms sorted by most common with the given filters on /api/symptom_statistics/most_common GET", async () => {
it("it should return list of symptoms sorted by most common with the given filters on /api/symptom_statistics GET", async () => {
let response = await chai
.request(server)
.get("/api/symptom_statistics/most_common")
.get("/api/symptom_statistics")
.query({country: "Ethiopia", date: date})
expect(response).to.have.status(200);
expect(response.body).to.be.an("array");
expect(response.body[0]).to.have.property("name", "Headaches");
expect(response.body).to.be.an("object");
expect(response.body.data).to.be.an("array");
expect(response.body).to.have.property("total");
expect(response.body.data[0]).to.have.property("count");

});

it("it should return list of symptoms sorted by most common with the given filters on /api/symptom_statistics/most_common GET", async () => {
it("it should return list of symptoms sorted by most common with the given filters on /api/symptom_statistics GET", async () => {
let response = await chai
.request(server)
.get("/api/symptom_statistics")
.query({district: "Bole", date: date})
expect(response).to.have.status(200);
expect(response.body).to.be.an("object");
expect(response.body.data).to.be.an("array");
expect(response.body).to.have.property("total");
expect(response.body.data[0]).to.have.property("count");

});

it("it should return the number of people with symptoms on /api/symptom_statistics/people GET", async () => {
let response = await chai
.request(server)
.get("/api/symptom_statistics/most_common")
.get("/api/symptom_statistics/people")
.query({district: "Bole", date: date})
expect(response).to.have.status(200);
expect(response.body).to.be.an("array");
expect(response.body[0]).to.have.property("name", "Headaches");
expect(response.body).to.be.an("object");
expect(response.body).to.have.property("result");

});
});

Expand Down Expand Up @@ -310,8 +239,20 @@ describe("Symptom Statistics API", function() {
.request(server)
.get("/api/symptom_statistics/logs")
expect(response).to.have.status(200);
expect(response.body[0]).to.have.property("status", "SYMPTOM_SUBMITTED");
expect(response.body[0]).to.have.property("current_symptoms");
expect(response.body).to.be.an("object");
expect(response.body.data[0]).to.have.property("status", "SYMPTOM_SUBMITTED");
expect(response.body.data[0]).to.have.property("current_symptoms");
});

it("it should return all symptom logs with the given filters on /api/symptom_statistics/logs GET", async () => {
let response = await chai
.request(server)
.get("/api/symptom_statistics/logs")
.query({status: "SYMPTOM_SUBMITTED"})
expect(response).to.have.status(200);
expect(response.body).to.be.an("object");
expect(response.body.data[0]).to.have.property("status", "SYMPTOM_SUBMITTED");
expect(response.body.data[0]).to.have.property("current_symptoms");
});

it("it should return symptom logs for a single user on /api/symptom_statistics/logs/user/:user_id GET", async () => {
Expand Down
28 changes: 14 additions & 14 deletions How to work with the mobile application.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
How to work with the COVID-19 Mobile Application :
1.The first step to install React Native is Download and Install below required software packages.
NodeJS : Download and install the latest NodeJS windows machine installer software package from https://nodejs.org .
Python : Download and install the latest Python windows installer package from https://Python.org .
2.Install react native using the command :
npm install -g react-native-cli
3.Install Android Studio and its SDK from:
https://developer.android.com/studio/index.html
4.Then clone this project in to your desired folder on your computer
How to work with the COVID-19 Mobile Application :

1.The first step to install React Native is Download and Install below required software packages.
NodeJS : Download and install the latest NodeJS windows machine installer software package from https://nodejs.org .
Python : Download and install the latest Python windows installer package from https://Python.org .

2.Install react native using the command :
npm install -g react-native-cli

3.Install Android Studio and its SDK from:
https://developer.android.com/studio/index.html

4.Then clone this project in to your desired folder on your computer

5.Then go in to the project folder and write "react-native run-android or react-native run-ios" to run it on your emulator or your phone
Loading

0 comments on commit 69cc808

Please sign in to comment.