Skip to content

Commit

Permalink
minor_project
Browse files Browse the repository at this point in the history
  • Loading branch information
diablo1408 committed Dec 31, 2020
0 parents commit e5f695b
Show file tree
Hide file tree
Showing 559 changed files with 308,144 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
EMAIL = "minorprojectcse2020@gmail.com"
PASSWORD = "wasd4321"
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.<br />
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.<br />
You will also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.<br />
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.<br />
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.<br />
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting

### Analyzing the Bundle Size

This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size

### Making a Progressive Web App

This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app

### Advanced Configuration

This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration

### Deployment

This section has moved here: https://facebook.github.io/create-react-app/docs/deployment

### `npm run build` fails to minify

This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
76 changes: 76 additions & 0 deletions controller/download/download_img.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const fs = require('fs');
const path = require('path');
const Vision = require("../../models/vision");
const util = require("util");


class DownLoad {

async process_genre(user,genre,req){
//mke folder of given genre
let FS_MKDIR = util.promisify(fs.mkdir);
try{
await FS_MKDIR(path.join("/home/utsav/Desktop", genre))
.then((user) => {
console.log('Directory created successfully!')
})
}
catch(error){
console.log('error while making folder');
}


let label_mapping = user[0].image_labels;
let found = label_mapping.find((ele)=>{return (ele.name === genre)});
let allimagesData = found["label"];

for(let i = 0;i<allimagesData.length;i++){
let img_name = allimagesData[i]["img_name"].substr(allimagesData[0]["img_name"].indexOf("-")+1);
let img_buffer = allimagesData[i]["img_buffer"];


let FS_WRITEFILE = util.promisify(fs.writeFile);
try{
await FS_WRITEFILE(path.join("/home/utsav/Desktop/"+genre,img_name), img_buffer,"base64")
.then(() => {
// console.log('file saved to ', img_name)
})
}
catch(err){
console.log(err);
}
}
}

handleRequest(req, res) {
// console.log(req)
const user_id = req.params.user_id;
const genreList = req.params.genres.split(',');
console.log(user_id,genreList);
try{
Vision.find({user_id : user_id})
.then(async (user)=>{



let promise = [];
for(let i = 0;i<genreList.length;i++){
promise.push(this.process_genre(user,genreList[i],req)
.catch((err)=>{
console.log(err,"error while inserting genre/s");
}));
}

await Promise.all(promise);

return res.status(200).json({"msg" : "Downloaded"})
})
.catch((err)=>{console.log(err);})
}
catch(err){
console.log(err);
}
}
};

module.exports = {DownLoad : DownLoad};
201 changes: 201 additions & 0 deletions controller/image/addImage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
const mongoose = require("mongoose");
const multer = require("multer");
const fs = require("fs");
const Vision = require("../../models/vision");
const {get_features} = require('../../predict');
const util = require('util');


//for multiple file

class AddImage {

constructor() {
this.readFile = util.promisify(fs.readFile);
}

getStuff(path) {
return this.readFile(path);
}

async process_image(user,element,req){

// console.log(user);

let features = await get_features(element.path);
let feature_list = features.slice(0,5);
await this.getStuff(element.path).then(async(data)=>{

let image_mapping = user[0].image;
// console.log(image_mapping);

image_mapping.push({img_name : element.filename,img_label : feature_list,img_data:data});


//for labels
let label_mapping = user[0].image_labels;
if(label_mapping.length == 0){
label_mapping.push({name : "All" ,label : {img_name : element.filename,img_buffer : data}});
}
else{
let found = label_mapping.find((ele)=>{return (ele.name === 'All')});
if(found !== undefined){
found.label.push({img_name : element.filename,img_buffer : data});
}
}

feature_list.forEach(function (item) {

let found = label_mapping.find((ele)=>{return (ele.name === item.name)});
if(found !== undefined){
found.label.push({img_name : element.filename,img_buffer : data});
}
else{
label_mapping.push({name : item["name"] ,label : {img_name : element.filename,img_buffer : data}});
}
});

const user_id = req.body.user_id;
Vision.updateOne({user_id : user_id},{
$set: { 'image': image_mapping ,
'image_labels' : label_mapping
}}).then((user)=>{
console.log(user)
});

}).catch((err)=>{
console.log(err,"err in line 32");
});
}

handleRequest(req, res) {


const user_id = req.body.user_id;
// console.log(req.files);

try{
Vision.find({user_id : user_id})
.then(async(user)=>{

let promise = [];
req.files.forEach((element)=>{
promise.push(this.process_image(user,element,req)
.catch((err)=>{
console.log(err,"error while inserting image/s");
}));
});

// console.log("promise",promise);

await Promise.all(promise);

let found_label = user[0].image_labels;
let found_filter_label = found_label.find((ele)=>{return (ele.name === "All")});
return res.status(200).json(found_filter_label["label"]);

})
.catch((err)=>{console.log("err line 94",err)})
}
catch(err){
return res.status(405).send("err in 97th line");
}
}
};

module.exports = {AddImage : AddImage};



//for Single file


// const mongoose = require("mongoose");
// const multer = require("multer");
// const fs = require("fs");
// const Vision = require("../../models/vision");
// const {get_features} = require('../../predict');
// const util = require('util');


// class AddImage {


// handleRequest(req, res) {


// const user_id = req.body.user_id;
// // console.log(req.files);

// Vision.find({user_id : user_id})
// .then(async(user)=>{

// // for(let i=0;i<req.files.length;i++){
// let features = await get_features(req.file.path);
// let feature_list = features.slice(0,5);

// let FS_READFILE = util.promisify(fs.readFile);
// try{

// FS_READFILE(req.file.path)
// .then((data) => {

// const contentType = req.file.mimetype;
// let image_mapping = user[0].image;
// // console.log(image_mapping);

// image_mapping.push({img_name : req.file.filename,img_label : feature_list,img_data:data});


// //for labels
// let label_mapping = user[0].image_labels;
// if(label_mapping.length == 0){
// label_mapping.push({name : "All" ,label : {img_name : req.file.filename,img_buffer : data}});
// }
// else{
// let found = label_mapping.find((ele)=>{return (ele.name === 'All')});
// if(found !== undefined){
// found.label.push({img_name : req.file.filename,img_buffer : data});
// }
// }

// feature_list.forEach(function (item) {

// let found = label_mapping.find((ele)=>{return (ele.name === item.name)});
// if(found !== undefined){
// found.label.push({img_name : req.file.filename,img_buffer : data});
// }
// else{
// label_mapping.push({name : item["name"] ,label : {img_name : req.file.filename,img_buffer : data}});
// }
// });

// const user_id = req.body.user_id;
// Vision.updateOne({user_id : user_id},{
// $set: { 'image': image_mapping ,
// 'image_labels' : label_mapping
// }}).then((user)=>{
// console.log(user)
// });

// let found_label = user[0].image_labels;
// let found_filter_label = found_label.find((ele)=>{return (ele.name === "All")});
// return res.status(200).json(found_filter_label["label"]);

// })
// }
// catch(err){
// console.log(err);
// }
// // }

// // return res.status(200).send({"hello" : "all saved"});
// })
// .catch((error)=>{
// console.log(error);
// return res.status(400).json({"msg":error})
// });
// }
// };

// module.exports = {AddImage : AddImage};
Loading

0 comments on commit e5f695b

Please sign in to comment.