Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilioBerumen90 committed Sep 17, 2023
2 parents 0ec8565 + 3c643af commit 0d9c5a7
Show file tree
Hide file tree
Showing 142 changed files with 31,182 additions and 89 deletions.
79 changes: 53 additions & 26 deletions PathMate/AI_MindsDB_Models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import mysql.connector
import os
from accounts.models import UserProfileTable
from datetime import datetime

class SingletonMeta(type):
_instances = {}
Expand All @@ -10,43 +12,68 @@ def __call__(cls, *args, **kwargs):
cls._instances[cls] = instance
return cls._instances[cls]


'''
host=os.environ.get("DB_HOST", "cloud.mindsdb.com"),
user=os.environ.get("DB_USER", "your_user"),
password=os.environ.get("DB_PASS", "your_password"),
port=os.environ.get("DB_PORT", "3306")
'''

class AIMindsDBModels(metaclass=SingletonMeta):
def __init__(self):
#%env:KEY_NAME=value
if not hasattr(self, 'mydb'):
self.mydb = mysql.connector.connect(
host=os.environ.get("DB_HOST", "cloud.mindsdb.com"),
user=os.environ.get("DB_USER", "your_user"),
password=os.environ.get("DB_PASS", "your_password"),
port=os.environ.get("DB_PORT", "3306")
host="cloud.mindsdb.com",
user="pathmateai@gmail.com",
password="PathMateAI",
port=3306
)
self.cursor = self.mydb.cursor()


def fetch_user_profile(self, user_id):
try:
user_profile = UserProfileTable.objects.get(User_id=user_id)
return user_profile
except UserProfileTable.DoesNotExist:
return None


def generate_query(self, model_name, user_profile):
now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
execute_query = "SELECT response from " + model_name + " WHERE "
#execute_query += f"User_Name = '{user_profile.User_Name}' AND "
#execute_query += f"User_Country = '{user_profile.User_Country}' AND "
#execute_query += f"Job = '{user_profile.Job}' AND "
#execute_query += f"User_Age = '{user_profile.User_Age}' AND "
execute_query += f"User_Major = '{user_profile.User_Major}' AND "
execute_query += f"User_GraduationDate = '{user_profile.User_GraduationDate}' AND "
execute_query += f"Level_Study = '{user_profile.Level_Study}' AND "
execute_query += f"Start_Date = '{now}' AND "
#execute_query += f"Location = '{user_profile.Location}' AND "
execute_query += f"Goals = '{user_profile.Goals}' AND "
#execute_query += f"Goal_Deadline = '{user_profile.Goal_Deadline}' AND "
#execute_query += f"Needs_Visa_Sponsorship = '{user_profile.Needs_Visa_Sponsorship}' AND "
execute_query += f"Skill_Set = '{user_profile.Skill_Set}'"
#execute_query += f"User_Availabilty = '{user_profile.User_Availabilty}' "
return execute_query


def execute_query(self, query):
self.cursor.execute(query)
return self.cursor.fetchall()

def generate_query(self, model_name):
query = 'SELECT response from ' + (model_name) + ' WHERE '
#query += f"User_Name = '{get from accounts_userprofiletable the User_Name}' "
for row in self.cursor:
output = row[0] # Assuming the text is the first field in the result row
sections = output.split("\n\n") #Splitting the text into sections

result_str = ""
for section in sections:
result_str += f"{section}\n\n"
with open("logs.txt", "a") as f:
f.write("Result String: ")
f.write(result_str)
f.write("\n\n")
return result_str

def fetch_events(cursor):
query = "SELECT user, title, description, start_time, end_time, special_event_code FROM your_event_table"
cursor.execute(query)
events = []
for row in cursor:
event = {
"user": row[0],
"title": row[1],
"description": row[2],
"start_time": row[3],
"end_time": row[4],
"special_event_code": row[5]
}
events.append(event)
return events



Expand Down
17 changes: 17 additions & 0 deletions accounts/migrations/0006_userprofiletable_user_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.5 on 2023-09-16 20:24

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("accounts", "0005_userprofiletable_user_availabilty"),
]

operations = [
migrations.AddField(
model_name="userprofiletable",
name="User_id",
field=models.IntegerField(default=0),
),
]
2 changes: 2 additions & 0 deletions accounts/models/databaseuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class UserProfileTable(models.Model):
Needs_Visa_Sponsorship = models.CharField(max_length=300)

User_Availabilty = models.CharField(max_length=100)

User_id = models.IntegerField(default=0)



Expand Down
4 changes: 3 additions & 1 deletion accounts/views/userdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def userdata(request):
skill_set = request.POST.get("Skill_Set")
needs_visa_sponsorship = request.POST.get("Needs_Visa_Sponsorship")
user_availabilty = request.POST.get("User_Availabilty")
user_id = request.user.id

UserProfileTable.objects.create(User_Major=user_major,
User_Name=user_name,
Expand All @@ -31,7 +32,8 @@ def userdata(request):
Goal_Deadline=goal_deadline,
Skill_Set=skill_set,
Needs_Visa_Sponsorship=needs_visa_sponsorship,
User_Availabilty=user_availabilty
User_Availabilty=user_availabilty,
user_id=user_id
)
return redirect("calendarapp:calendar")
return render(request, "accounts/profile-creation.html")
Expand Down
63 changes: 48 additions & 15 deletions calendarapp/AI_EventFactory.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,63 @@
from calendarapp.models import Event
from django.contrib.auth.models import User
from accounts.models import User

from datetime import datetime, timedelta
from django.utils.dateparse import parse_datetime
from django.db.models import Max
from PathMate.AI_MindsDB_Models import AIMindsDBModels

import re
from dateutil.parser import parse
#Q: What is the pip install for dateutil.parser? A: pip install python-dateutil

# This function can later be enhanced to use AI for event creation
def create_auto_events(_user):
def create_auto_events(_user_id):
ai_db = AIMindsDBModels()
start_time = datetime(2023, 9, 20, 14, 0)
end_time = datetime(2023, 9, 20, 15, 0)

last_event = Event.objects.all().aggregate(Max('id'))
last_id = last_event['id__max'] or 0
for i in range(2):
new_id = last_id + i + 1
unique_id = datetime.now().strftime("%Y%m%d%H%M%S%f")

profile = ai_db.fetch_user_profile(_user_id)
if profile is None:
with open("logs.txt", "a") as f:
f.write("USER NOT FOUND: ")
f.write("\n\n")
return

query = ai_db.generate_query("mindsdb.roadmap_calendar_planner_model", profile)

event_string = ai_db.execute_query(query)

pattern = re.compile(r'title = "(?P<title>.*?)"[,]?\n'
r'description = "(?P<description>.*?)"[,]?\n'
r'start_time = "(?P<start_time>.*?)"[,]?\n'
r'end_time = "(?P<end_time>.*?)"[,]?\n'
r'special_event_code = (?P<special_event_code>\d+)')


matches = pattern.findall(event_string)
with open("logs.txt", "a") as f:
#log matches.size
f.write("Matches found: " + str(len(matches)))
f.write("\n\n")

for match in matches:
title, description, start_time, end_time, special_event_code = match
start_time = parse(start_time) # Convert to datetime object
end_time = parse(end_time) # Convert to datetime object
special_event_code = int(special_event_code) # Convert to integer

# Create event
Event.objects.create(
user=_user,
title=f"Auto Event {i+1} {unique_id})",
description=f"Description for auto event {new_id}",
user=User.objects.get(id=_user_id),
title=title,
description=description,
start_time=start_time,
end_time=end_time
end_time=end_time,
special_event_code=special_event_code
)

start_time += timedelta(hours=1)
end_time += timedelta(hours=1)




def delete_event(_event):
Expand Down
17 changes: 17 additions & 0 deletions calendarapp/migrations/0003_event_special_event_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.5 on 2023-09-16 20:24

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("calendarapp", "0002_auto_20210717_1606"),
]

operations = [
migrations.AddField(
model_name="event",
name="special_event_code",
field=models.IntegerField(default=0),
),
]
1 change: 1 addition & 0 deletions calendarapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
path('trigger_auto_events/', views.trigger_auto_events, name='trigger_auto_events'),

path('delete_event/<int:event_id>/', views.trigger_delete_event, name='delete_event'),
path("opt/", views.opt)

]
4 changes: 3 additions & 1 deletion calendarapp/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
EventMemberDeleteView,
trigger_auto_events,
trigger_delete_event,
opt,
)


Expand All @@ -23,5 +24,6 @@
add_eventmember,
EventMemberDeleteView,
trigger_auto_events,
trigger_delete_event
trigger_delete_event,
opt,
]
9 changes: 6 additions & 3 deletions calendarapp/views/other_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ def post(self, request, *args, **kwargs):

def trigger_auto_events(request):
if request.user.is_authenticated:
create_auto_events(request.user)

user_id = request.user.id
create_auto_events(user_id)
return redirect("calendarapp:calendar")

def trigger_delete_event(request, event_id):
Expand All @@ -166,4 +166,7 @@ def trigger_delete_event(request, event_id):
except Event.DoesNotExist:
return JsonResponse({'success': False})
else:
return JsonResponse({'success': False})
return JsonResponse({'success': False})

def opt(request):
return render(request, "calendarapp/opt.html")
64 changes: 64 additions & 0 deletions logs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
Result String: title = "Advanced C++ Course",
description = "To enhance your skills in C++, consider taking an advanced course. This will help you stand out in your internship applications. You can take this course on a weekly basis for 2 months. <link to Coursera C++ course>",
start_time = "2023-09-17 09:00:00",
end_time = "2023-11-17 17:00:00",
special_event_code = 2

title = "Unreal Engine Masterclass",
description = "To further improve your game development skills, take a masterclass in Unreal Engine. This can be done twice a week for 3 months. <link to Udemy Unreal Engine course>",
start_time = "2023-09-17 09:00:00",
end_time = "2023-12-17 17:00:00",
special_event_code = 2

title = "Game Documentation Workshop",
description = "Attend a workshop on game documentation to enhance your understanding and skills. This can be a one-time event. <link to Eventbrite Game Documentation Workshop>",
start_time = "2023-09-17 09:00:00",
end_time = "2023-09-17 17:00:00",
special_event_code = 2

title = "NVIDIA Internship Application",
description = "Start applying for the NVIDIA internship. This should be done weekly for 3 months. <link to NVIDIA Internship Application>",
start_time = "2023-09-17 09:00:00",
end_time = "2023-12-17 17:00:00",
special_event_code = 3

title = "Game Developers Conference",
description = "Attend the Game Developers Conference for networking opportunities. This is a one-time event. <link to GDC Registration>",
start_time = "2023-09-17 09:00:00",
end_time = "2023-09-17 17:00:00",
special_event_code = 4

title = "Personal Project",
description = "Start a personal game development project to showcase your skills. This can be done daily for 4 months. <link to GitHub>",
start_time = "2023-09-17 09:00:00",
end_time = "2023-01-17 17:00:00",
special_event_code = 5

title = "LinkedIn Profile Update",
description = "Update your LinkedIn profile to reflect your new skills and projects. This can be done once a month. <link to LinkedIn>",
start_time = "2023-09-17 09:00:00",
end_time = "2023-12-17 17:00:00",
special_event_code = 5

title = "Portfolio Update",
description = "Update your portfolio with your new skills and projects. This can be done once a month. <link to Behance>",
start_time = "2023-09-17 09:00:00",
end_time = "2023-12-17 17:00:00",
special_event_code = 5

title = "Mock Interviews",
description = "Practice your interview skills with mock interviews. This can be done weekly for 2 months. <link to Pramp>",
start_time = "2023-09-17 09:00:00",
end_time = "2023-11-17 17:00:00",
special_event_code = 5

title = "Resume Update",
description = "Update your resume with your new skills and projects. This can be done once a month. <link to Canva Resume Templates>",
start_time = "2023-09-17 09:00:00",
end_time = "2023-12-17 17:00:00",
special_event_code = 5



Matches found: 10

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ urllib3
virtualenv
wrapt
setuptools
python-dateutil
mysql-connector-python
Loading

0 comments on commit 0d9c5a7

Please sign in to comment.