This is the official Repo for PsyCred during the 30 Hour Hackathon "MATHack"
link: https://github.com/tarunkay7/PsyCred
There are 4 essential commands you use in Git which are
git add PATH/TO.FILE
: Adds the file to the staging areagit commit -m "COMMIT MESSAGE"
: Commits the filegit push -u origin
: Pushes the file to remote repogit pull
: Pulls changes from report repo
The Users
table stores information about users.
Column Name | Data Type | Constraints | Description |
---|---|---|---|
Unique_id | INTEGER | PRIMARY KEY, AUTOINCREMENT | Unique identifier for each user |
name | VARCHAR | Name of the user | |
age | INTEGER | CHECK (age > 18) | Age of the user (must be over 18) |
phone_number | TEXT | UNIQUE | Phone number of the user |
pincode | INTEGER | Pincode of the user |
The Scores
table stores scores related to users.
Column Name | Data Type | Constraints | Description |
---|---|---|---|
user_id | INTEGER | Foreign key referencing the Unique_id column in the Users table | |
demographic_score | DECIMAL | DEFAULT 0 | Score representing user's demographic data |
psychometric_test_score | DECIMAL | DEFAULT 0 | Score representing user's psychometric test performance |
The creditworthiness_score
table stores creditworthiness scores of users.
Column Name | Data Type | Constraints | Description |
---|---|---|---|
user_id | INTEGER | PRIMARY KEY | Primary key referencing the Unique_id column in the Users table |
creditworthiness_score | DECIMAL | DEFAULT 0 | Score representing user's creditworthiness |
- The
user_id
column in theScores
table references theUnique_id
column in theUsers
table. - The
user_id
column in thecreditworthiness_score
table references theUnique_id
column in theUsers
table.
This schema is designed to store user information, including demographic details, psychometric test scores, and creditworthiness scores. Foreign key constraints ensure referential integrity between related tables.
This document provides documentation for the user management APIs.
-
URL:
/api/users/v1/create_user
-
Method:
POST
-
Description: Creates a new user in the database.
-
Request Body:
{ "name": "John Doe", "age": 30, "phone_number": "1234567890", "education": "Bachelor's Degree", "pincode": "12345" }
-
Response:
-
Success (201):
{ "message": "User created successfully" }
-
Error (400):
{ "error": "Incomplete user data" }
OR
{ "error": "Invalid request body" }
-
Error (500):
{ "error": "Internal Server Error" }
-
-
URL:
/api/users/v1/get_user/<int:user_id>
-
Method:
GET
-
Description: Retrieves user details by ID from the database.
-
Parameters:
user_id
: Unique identifier of the user.
-
Response:
-
Success (200):
{ "Unique_id": 1, "name": "John Doe", "age": 30, "phone_number": "1234567890", "education": "Bachelor's Degree", "pincode": "12345" }
-
Error (404):
{ "error": "User not found" }
-
Error (500):
{ "error": "Internal Server Error" }
-
-
URL:
/api/users/v1/update_user/<int:user_id>
-
Method:
PUT
-
Description: Updates user details by ID in the database.
-
Parameters:
user_id
: Unique identifier of the user.
-
Request Body:
{ "name": "John Doe", "age": 35, "phone_number": "9876543210", "education": "Master's Degree", "pincode": "54321" }
-
Response:
-
Success (200):
{ "message": "User updated successfully" }
-
Error (404):
{ "error": "User not found" }
-
Error (500):
{ "error": "Internal Server Error" }
-
-
URL:
/api/v1/users/delete_user/<int:user_id>
-
Method:
DELETE
-
Description: Deletes a user by ID from the database.
-
Parameters:
user_id
: Unique identifier of the user.
-
Response:
-
Success (200):
{ "message": "User deleted successfully" }
-
Error (404):
{ "error": "User not found" }
-
Error (500):
{ "error": "Internal Server Error" }
Below is the documentation for the provided API endpoint in Markdown format:
-
- URL:
/api/users/v1/verify_password
- Method:
POST
- Description: Verifies the user's phone number and generates an OTP (One-Time Password) for authentication.
- Request Body:
- Content-Type:
application/json
- Parameters:
phone_number
: Phone number of the user.
- Example:
{ "phone_number": "1234567890" }
- Content-Type:
- Responses:
- Success (200):
- Description: OTP generated successfully.
- Body:
{ "message": "OTP generated successfully", "otp": "<generated_otp>" }
- Example:
{ "message": "OTP generated successfully", "otp": "123456" }
- Error (400):
- Description: Phone number is missing in the request.
- Body:
{ "error": "Phone number is required" }
- Error (404):
- Description: User not found in the database.
- Body:
{ "error": "User not found" }
- Error (500):
- Description: Internal server error occurred.
- Body:
{ "error": "<error_message>" }
- Success (200):
- Notes:
- The API generates a random 6-digit OTP for demonstration purposes.
- The generated OTP is printed in the console for demonstration purposes. In a real application, it should be sent to the user's phone number via SMS or another secure method.
This function inserts data into the database and automatically computes metrics based on the pincode.
- Parameters:
age
: Age of the individual.education
: Education level of the individual.pincode
: Pincode of the area where the individual resides.
This function generates training data by calling insert_train_data()
.
- Parameters:
n
: Number of data points to generate.
This function populates the DistrictInfo
table by scraping data from a website.
- Parameters:
conn
: SQLite database connection object.
This function creates the Users
table in the database.
This function creates the Scores
table in the database.
This function creates the creditworthiness_score
table in the database.
This function creates the DistrictInfo
table in the database and populates it with data.
This function creates the TrainData
table in the database.
This function drops the Users
table from the database.
This function computes a demographic score based on age, education level, district growth, and literacy rate.
- Parameters:
age
: Age of the individual.edu
: Education level of the individual.growth
: Growth rate of the district.literacy
: Literacy rate of the district.
This function checks the formula()
function by applying it to the data in the TrainData
table and printing the results.
- Parameters:
formula
: The demographic score calculation formula.
- URL:
/api/users/v1/generate_otp
- Method:
GET
- Description: Generates a one-time password (OTP) for user authentication.
- Responses:
- Success (200):
- Description: OTP generated successfully.
- Body:
{ "otp": "<generated_otp>" }
- Example:
{ "otp": "123456" }
- Success (200):
- Notes:
- The generated OTP is stored globally for verification purposes.
- URL:
/api/users/v1/verify_otp
- Method:
POST
- Description: Verifies the provided OTP.
- Request Body:
- Content-Type:
application/json
- Parameters:
otp
: One-time password for verification.
- Example:
{ "otp": "123456" }
- Content-Type:
- Responses:
- Success (200):
- Description: OTP verification successful.
- Body:
{ "message": "OTP verification successful" }
- Error (400):
- Description: OTP is missing in the request.
- Body:
{ "error": "OTP is required" }
- Success (200):
- URL:
/api/hyperleap/v1/persona
- Method:
POST
- Description: Retrieves persona information using Hyperleap API.
- Request Body:
- Content-Type:
application/json
- Parameters:
personaId
: ID of the persona.questions
: List of questions related to the persona.
- Example:
{ "personaId": "123", "questions": ["What is your name?", "How old are you?"] }
- Content-Type:
- Responses:
- Success (200):
- Description: Persona information retrieved successfully.
- Body: Response from the Hyperleap API.
- Error (500):
- Description: Internal server error occurred.
- Body:
{ "error": "<error_message>" }
- Success (200):
- URL:
/gen_questions
- Method:
GET
- Description: Generates questions using Hyperleap API based on provided answers.
- Request Body:
- Content-Type:
application/json
- Parameters:
- Questions and corresponding answers.
- Example:
{ "Q1": "Question 1", "A1": "Answer 1", ... "Q10": "Question 10", "A10": "Answer 10" }
- Content-Type:
- Responses:
- Success (200):
- Description: Questions generated successfully.
- Body: Generated questions.
- Error (status code):
- Description: Failed to generate questions.
- Body:
{ "error": "Failed to send prompt" }
- Success (200):
- URL:
/rate_answers
- Method:
GET
- Description: Rates provided answers using Hyperleap API.
- Request Body:
- Content-Type:
application/json
- Parameters:
- Questions and corresponding answers.
- Example:
{ "Q1": "Question 1", "A1": "Answer 1", "Q2": "Question 2", "A2": "Answer 2" }
- Content-Type:
- Responses:
- Success (200):
- Description: Answers rated successfully.
- Body: Rated answers.
- Error (status code):
- Description: Failed to rate answers.
- Body:
{ "error": "Failed to send prompt" }
- Success (200):