Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
anshumyname authored Mar 22, 2020
2 parents 7743ade + 6e0b61e commit 5c38c96
Show file tree
Hide file tree
Showing 18 changed files with 393 additions and 705 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@ Along with labours, it would be a convenient method for contractors as well and
- Flask
- Flutter
- SQLite3
- Google Map API
- Sklearn

## Usage of App
- Install the app on your android
- After installtion if you are a contractor you need to register yourself

(NOTE - It is assumed that the laborers will be registered on database with their details)
- The next screen will take you to options where you need to input the work to be done and select which skill laborers you want including how many of them.
- After reciveing acceptance from the laborer you will see on the screen the labor details such as his/her name,age,gender,etc.
- That's all you got the suitable laborers required for your work.


## Future Goals
- Ensuring correct information on each labourer’s and contractor’s side.
- Automatic skill selection using only work type.
Expand Down
116 changes: 74 additions & 42 deletions database/database.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
''' Entering, retrieving and maintaining the labourer's database. '''

import sqlite3
import random
import time
Expand All @@ -7,22 +9,24 @@
cursor = conn.cursor()

cursor.execute("SELECT max(labourer_id) from labourer_details")
global count_labourers
count_labourers = cursor.fetchone()[0]

skill_2 = {1: 7,
2: 6,
3: 9,
4: 7,
5: 6,
6: 5,
7: 10,
8: 8,
9: 8,
10: 6
}
2: 6,
3: 9,
4: 7,
5: 6,
6: 5,
7: 10,
8: 8,
9: 8,
10: 6
}


def create_table():
''' creating the table in the database '''
cursor.execute('''CREATE TABLE IF NOT EXISTS labourer_details(
labourer_id INTEGER,
name TEXT,
Expand All @@ -31,33 +35,39 @@ def create_table():
gender INTEGER,
latitudes REAL,
longitudes REAL,
income INTEGER
income INTEGER,
contact TEXT
)''')


def data_entry(name, age, skill, gender,
latitudes, longitudes, income):
latitudes, longitudes, income, contact):
'''Entering data into the database'''
global count_labourers
labourer_id = count_labourers + 1

cursor.execute('''INSERT INTO labourer_details (
labourer_id, name, age, skill, gender,
latitudes, longitudes, income
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
latitudes, longitudes, income, contact
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
''', (
labourer_id, name, age, skill, gender,
latitudes, longitudes, income
latitudes, longitudes, income, contact
))
count_labourers = count_labourers + 1
conn.commit()


def find_distance(contractor_lat, contractor_long,
labour_lat, labour_long):
'''finding distance between two co-ordinates on map'''
coord1 = (contractor_lat, contractor_long)
coord2 = (labour_lat, labour_long)
return round(dis(coord1, coord2).km, 3)


def data_retrieval(skill, latitudes, longitudes):
'''retreiving the data from database to be sent to the model'''
cursor.execute(
f'''SELECT * FROM labourer_details WHERE skill={skill}'''
)
Expand All @@ -69,34 +79,56 @@ def data_retrieval(skill, latitudes, longitudes):
latitudes, longitudes, row[5], row[6]
))
input_data[id_r].append(skill_2[skill])
print(input_data)
# /print(input_data)
return input_data


def get_complete_details(id_, dist):
'''getting details to be sent to the contractor'''
cursor.execute(
f'''SELECT * FROM labourer_details WHERE labourer_id={id_}'''
)
jsondata = {}
for row in cursor.fetchall():
jsondata["name"] = row[1]
jsondata["age"] = row[2]
if row[4] == 1:
jsondata["gender"] = "male"
else:
jsondata["gender"] = "female"
jsondata["distance"] = dist
jsondata["contact"] = row[8]

return jsondata


def close_databae():
'''closing the database'''
cursor.close()
conn.close()


if __name__ == "__main__":
pass
# create_table()
# names = ['tanmay', 'anshuman', 'ankan', 'shreyash',
# 'raju', 'babu rao', 'shyam', 'hello', 'world']
# for i in range(51):
# labourer_id = i+1
# name = random.choice(names)
# age = random.randint(18, 60)
# skill = random.randint(1, 10)
# gender = random.randint(0, 1)
# latitudes = round(random.uniform(23.65, 23.85), 3)
# longitudes = round(random.uniform(86.30, 86.50), 3)
# income = random.randint(1, 10)*100

# data_entry(name, age, skill, gender,
# latitudes, longitudes, income)
# time.sleep(1)
# print(skill[3])
# data_retrieval(5, 23.43, 86.5)
# cursor.close()
# conn.close()

# cor1 = (23.745541, 86.343521)
# cor2 = (23.412358, 85.439989)

# print(distance(cor1, cor2))

''' Generating random datasets for testing'''
create_table()
names = ['tanmay', 'anshuman', 'ankan', 'shreyash',
'raju', 'babu rao', 'shyam', 'hello', 'world']
for i in range(51):
labourer_id = i+1
name = random.choice(names)
age = random.randint(18, 60)
skill = random.randint(1, 10)
gender = random.randint(0, 1)
latitudes = round(random.uniform(23.65, 23.85), 3)
longitudes = round(random.uniform(86.30, 86.50), 3)
income = random.randint(1, 10)*100
contact = ''.join(["{}".format(random.randint(0, 9))
for num in range(0, 10)])
data_entry(name, age, skill, gender,
latitudes, longitudes, income, contact)

# time.sleep(1)
data_retrieval(5, 23.43, 86.5)
cursor.close()
conn.close()
Binary file modified database/labourers.db
Binary file not shown.
33 changes: 26 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

obj = predictor.Model()

skills = {"Carpentary": [1, 7, "-"],
skills = {"Carpentry": [1, 7, "-"],
"Painting": [2, 6, "+"],
"Masonry": [3, 9, "-"],
"Plumbing": [4, 7, "+"],
Expand All @@ -19,28 +19,47 @@
"Fitter": [10, 6, "-"]
}

gender = {"male": 1,
"female": 2}


@app.route("/add_database", methods=['POST'])
def add_labour_database():
'''addition to the labourer's database'''
if request.method == 'POST':
data = request.json

db.data_entry(data["name"], data["age"], skills[data["skills"]][0], data["gender"],
round(data["location"]["latitude"],3), round(data["location"]["longitude"], 3), 0)
db.data_entry(data["name"], data["age"], skills[data["skills"]][0], gender[data["gender"].lower()],
round(data["location"]["latitude"], 3), round(data["location"]["longitude"], 3), 0)
return 'OK'


@app.route("/get_details", methods=['GET', 'POST'])
def get_details_from_database():
'''getting data from database and predicting the labourers. '''
if request.method == 'POST':
data = request.json
skill = skills[data["skill"]]
input_data = db.data_retrieval(skill[0], round(data["location"]["latitude"], 3),
round(data["location"]["longitude"], 3))
round(data["location"]["longitude"], 3))

pre, index = obj.preprocess_input(input_data, skill[2])
ans = obj.predict(pre, skill[2], index)
return 'OK'

ans = {k: v for k, v in sorted(ans.items(), key=lambda item: item[1])}

jsondata = []

for id_ in ans:
jsondata.append(db.get_complete_details(id_, input_data[id_][3]))

jsondata = json.dumps(jsondata)
print(jsondata)
json_data={
'prediction':{

}
}
return jsondata


if __name__ == "__main__":
Expand Down
14 changes: 7 additions & 7 deletions model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
from pickle import dump, load

class Model:
model_positive=load(open('model+ve.pkl', 'rb'))
xscaler_poisitive=load(open('xscaler+ve.pkl', 'rb'))
yscaler_positive=load(open('yscaler+ve.pkl', 'rb'))
model_negative=load(open('model-ve.pkl', 'rb'))
xscaler_negative=load(open('xscaler-ve.pkl', 'rb'))
yscaler_negative=load(open('yscaler-ve.pkl', 'rb'))
poly=load(open('poly.pkl', 'rb'))
model_positive=load(open('model/model+ve.pkl', 'rb'))
xscaler_positive=load(open('model/xscaler+ve.pkl', 'rb'))
yscaler_positive=load(open('model/yscaler+ve.pkl', 'rb'))
model_negative=load(open('model/model-ve.pkl', 'rb'))
xscaler_negative=load(open('model/xscaler-ve.pkl', 'rb'))
yscaler_negative=load(open('model/yscaler-ve.pkl', 'rb'))
poly=load(open('model/poly.pkl', 'rb'))

#If input is direct from database extract will prepare and drop unnecessary columns
def extract(self,df):
Expand Down
61 changes: 7 additions & 54 deletions rozgaar/lib/Contractor/Contractor_register.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart';
// import 'contractor_login.dart';

class ContractorRegistration extends StatefulWidget {
@override
_ContractorRegistrationState createState() =>
_ContractorRegistrationState();
_ContractorRegistrationState createState() => _ContractorRegistrationState();
}

class _ContractorRegistrationState extends State<ContractorRegistration> {
String _name, _phone;
// int _age;

final _formKey = GlobalKey<FormState>();

Expand Down Expand Up @@ -58,68 +55,25 @@ class _ContractorRegistrationState extends State<ContractorRegistration> {
_phone = val;
},
),

// TextFormField(
// decoration: InputDecoration(
// labelText: 'Location',
// ),
// validator: (val) {
// if (val.isEmpty) {
// return 'Location cannot be empty';
// }
// return null;
// },
// onSaved: (val) {
// _location = val;
// },
// ),
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
// children: <Widget>[
// RaisedButton(
// child: Text(
// 'Get location',
// ),
// onPressed: (){
// // var response = FetchLocation().returnLocation();
// // setState(() {
// // _location = response;
// // });
// FetchLocation().returnLocation().then((result) {
// print(result);
// setState(() {
// _location = result;
// });
// });
// },
// ),
// SizedBox(
// width: 50.0,
// ),
// Text(
// 'Latitude: ${_location['latitude']} Longitude: ${_location['longitude']}',
// ),
// ],
// ),
SizedBox(
height: 10.0,
),

RaisedButton(
textColor: Colors.white,
color: Colors.lightBlue,
padding: EdgeInsets.fromLTRB(9, 9, 9, 9),
splashColor: Colors.grey,
child: Text(
'Submit',
style: TextStyle(
color: Colors.blue,
),
style: TextStyle(fontSize: 18.0),
),
onPressed: () async {
if (_formKey.currentState.validate()) {
_formKey.currentState.save();
print('Registration successful');
Map data = {
'name': _name,
'phone': _phone, //**************
// 'location': _location,
'phone': _phone,
};
var jsonData = jsonEncode(data);
Response response = await post(
Expand All @@ -132,7 +86,6 @@ class _ContractorRegistrationState extends State<ContractorRegistration> {
}
},
)
// ,SizedBox(height: 24,)
],
),
),
Expand Down
Loading

0 comments on commit 5c38c96

Please sign in to comment.