Browse Source

added all courses to ProxSemestre

dmr1725 4 years ago
parent
commit
5a2092a39c

+ 1
- 1
Miupi Parser/Ciencias_Sociales.json
File diff suppressed because it is too large
View File


+ 1
- 1
Miupi Parser/Comunicaciones.json
File diff suppressed because it is too large
View File


+ 1
- 1
Miupi Parser/Humanidades.json
File diff suppressed because it is too large
View File


+ 1
- 1
Miupi Parser/Humanidades_Grad.json
File diff suppressed because it is too large
View File


BIN
organizar/__pycache__/organizar.cpython-38.pyc View File


+ 18
- 4
organizar/organizar.py View File

@@ -1,11 +1,14 @@
1 1
 import os, sys
2 2
 import json
3 3
 
4
-path1 = "C:/Users/diego/Documents/companion_app_gh/primer_sem"
5
-path2 = "C:/Users/diego/Documents/companion_app_gh/segundo_sem"
4
+
5
+path1 = "C:/Users/diego/Documents/companion_app/primer_sem"
6
+path2 = "C:/Users/diego/Documents/companion_app/segundo_sem"
7
+path3 = "C:/Users/diego/Documents/companion_app/Miupi Parser"
6 8
 
7 9
 dirs1 = os.listdir(path1)
8 10
 dirs2 = os.listdir(path2)
11
+dirs3 = os.listdir(path3)
9 12
 
10 13
 def orderFiles1(files1):
11 14
     i = 1
@@ -30,10 +33,21 @@ def orderFiles3(files1, files2, files3):
30 33
         files3.append({'file': files2[i]['file'], 'num': files1[i]['num']})
31 34
     return files3
32 35
 
36
+
37
+def orderFilesProxSemestre(files):
38
+    """ 
39
+    Organizing all the files from Miupi Parser to a single array. The array will contain each directory of each file
40
+    """
41
+    i = 1
42
+    for file in dirs3:
43
+        if file.endswith('.json'):
44
+            files.append({'file': file, 'num': i})
45
+            i += 1 # parse.py esta entre medio
46
+    return files
47
+
33 48
 files1 = orderFiles1([])
34 49
 files2 = orderFiles2([])
35 50
 files3 = []
36 51
 files3 = orderFiles3(files1, files2, files3)
37
-
38
-
52
+proxSemFiles = orderFilesProxSemestre([])
39 53
 

BIN
server/CompanionApp/__pycache__/models.cpython-38.pyc View File


BIN
server/CompanionApp/__pycache__/urls.cpython-38.pyc View File


BIN
server/CompanionApp/__pycache__/views.cpython-38.pyc View File


+ 18
- 0
server/CompanionApp/migrations/0015_auto_20201208_1214.py View File

@@ -0,0 +1,18 @@
1
+# Generated by Django 3.0.8 on 2020-12-08 16:14
2
+
3
+from django.db import migrations, models
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ('CompanionApp', '0014_auto_20201207_1613'),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.AlterField(
14
+            model_name='proximosemestre',
15
+            name='code',
16
+            field=models.CharField(max_length=15),
17
+        ),
18
+    ]

BIN
server/CompanionApp/migrations/__pycache__/0015_auto_20201208_1214.cpython-38.pyc View File


+ 1
- 1
server/CompanionApp/models.py View File

@@ -37,7 +37,7 @@ class Matricula(models.Model):
37 37
 class ProximoSemestre(models.Model):
38 38
     course_id = models.ForeignKey(Curso, on_delete=models.CASCADE, default=1)
39 39
     name = models.CharField(max_length=150)
40
-    code = models.CharField(max_length=9)
40
+    code = models.CharField(max_length=15)
41 41
     creditos = models.IntegerField(default=0)
42 42
     section = models.CharField(max_length=5, null=True, blank=True)
43 43
     prof = models.CharField(max_length=150, null=True, blank=True)

+ 3
- 2
server/CompanionApp/urls.py View File

@@ -12,13 +12,14 @@ urlpatterns = [
12 12
     url(r'^api/hello$', views.hello_world),
13 13
     url(r'^api/insertar_cursos$', views.insertarTodosLosCursos),
14 14
     url(r'^api/update_faculty$', views.updateFaculty),
15
-    # url(r'^api/find_course$', views.findCourse),
16 15
     url('api/find_course', views.findCourse),
16
+    url('api/select_course_prox_semestre', views.selectCourseProxSemestre),
17 17
     url(r'^api/add_taken_course$', views.addTakenCourse),
18 18
     url(r'^api/get_user_id$', views.getUserId),
19 19
     url('api/get_faculty_name', views.getFacultyUser),
20 20
     url('api/get_all_courses_user_has_taken', views.getAllCoursesUserHasTaken),
21 21
     url('api/get_all_courses_by_semester', views.getAllCoursesBySemester),
22
-    url('api/see_gpa', views.seeGPA)
22
+    url('api/see_gpa', views.seeGPA),
23
+    url('api/insertar_prox_sem_cursos', views.insertarTodosLosCursosProxSemestre)
23 24
 ]
24 25
 

+ 55
- 3
server/CompanionApp/views.py View File

@@ -3,7 +3,7 @@ import json
3 3
 sys.path.insert(1,'C:/Users/diego/Documents/companion_app/organizar/')
4 4
 
5 5
 
6
-from organizar import files3
6
+from organizar import files3, proxSemFiles
7 7
 
8 8
 
9 9
 from rest_auth.registration.views import SocialLoginView
@@ -15,7 +15,7 @@ from django.http.response import JsonResponse
15 15
 from rest_framework.parsers import JSONParser 
16 16
 from rest_framework import status
17 17
  
18
-from .models import Facultad, Curso
18
+from .models import Facultad, Curso, ProximoSemestre
19 19
 from .serializers import FacultadSerializer, CursoSerializer
20 20
 from rest_framework.decorators import api_view
21 21
 
@@ -91,6 +91,49 @@ def insertarTodosLosCursos(request):
91 91
                                 i += 1
92 92
         return JsonResponse({'message': 'se insertaron todos los cursos'}, status=status.HTTP_201_CREATED)
93 93
 
94
+@api_view(['POST',])
95
+def insertarTodosLosCursosProxSemestre(request):
96
+    if request.method == 'POST': 
97
+        for file in proxSemFiles:
98
+            path = "C:/Users/diego/Documents/companion_app/Miupi Parser"
99
+            with open(path + '/' + file['file']) as f:
100
+                data = json.load(f)
101
+                fac_id = file["num"] # this id comes from the file organizar. If the course does not exist in table Curso, use this id
102
+                for course in data:
103
+                    name = course["Nombre"]
104
+                    code = course["Curso"]
105
+                    creditos = int(course["Creditos"])
106
+                    section = course["Seccion"]
107
+                    prof = course["Profesor"]
108
+                    hours = course["Horario"]
109
+                    days = course["Dias"]
110
+                    rooms = course["Salones"]
111
+
112
+
113
+                    # seeing if course from json file already exists in table Curso
114
+                    cursor = connection.cursor()
115
+                    cursor.execute(f'SELECT id from "CompanionApp_curso" where code = \'{code}\'')
116
+                    course_id = cursor.fetchone()
117
+
118
+                    # if course does not exist in table Curso, create the course in table Course and create the course in table ProximoSemestre
119
+                    if course_id == None:
120
+                        # create course
121
+                        cursor = connection.cursor()
122
+                        cursor.execute(f'INSERT INTO "CompanionApp_curso" (name, code, creditos, fac_id_id) VALUES (\'{name}\', \'{code}\', {creditos}, {fac_id})')
123
+                        
124
+                         # seeing again if course from json file already exists in table Curso to fetch course_id
125
+                        cursor = connection.cursor()
126
+                        cursor.execute(f'SELECT id from "CompanionApp_curso" where code = \'{code}\'')
127
+                        course_id = cursor.fetchone()
128
+                       
129
+                  
130
+                    # insert course to the table ProxSemestre
131
+                    course_id = course_id[0]
132
+                    cursor = connection.cursor()
133
+            
134
+                    cursor.execute(f'INSERT INTO "CompanionApp_proximosemestre" (name, code, creditos, section, prof, hours, days, rooms, course_id_id) VALUES (\'{name}\', \'{code}\', {creditos}, \'{section}\', \'{prof}\', \'{hours}\', \'{days}\', \'{rooms}\', {course_id})')
135
+          
136
+        return JsonResponse({'message': 'se insertaron todos los cursos'}, status=status.HTTP_201_CREATED)
94 137
 
95 138
 
96 139
 @api_view(['PATCH',])
@@ -121,8 +164,17 @@ def findCourse(request):
121 164
         courses = list(courses.values())
122 165
         return JsonResponse({'list': courses}, status=status.HTTP_200_OK)
123 166
 
167
+# find courses in our ProximoSemestre table
168
+@api_view(['GET',])
169
+def selectCourseProxSemestre(request):
170
+    if request.method == 'GET':
171
+        course_code = request.query_params['code'].upper()
172
+        courses = ProximoSemestre.objects.filter(code__contains=course_code)[:10]
173
+        courses = list(courses.values())
174
+        return JsonResponse({'list': courses}, status=status.HTTP_200_OK)
175
+
124 176
 
125
-@api_view(['POST'])
177
+@api_view(['POST',])
126 178
 def addTakenCourse(request):
127 179
     if request.method == 'POST':
128 180
         # request params