forked from cesar-david-quiros-sierra/ISIS1225-SampleMVC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
139 lines (108 loc) · 3.79 KB
/
model.py
File metadata and controls
139 lines (108 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
"""
* Copyright 2020, Departamento de sistemas y Computación,
* Universidad de Los Andes
*
*
* Desarrolado para el curso ISIS1225 - Estructuras de Datos y Algoritmos
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along withthis program. If not, see <http://www.gnu.org/licenses/>.
*
* Contribuciones:
*
* Dario Correal - Version inicial
* Santiago Arteaga - Otras versiones
"""
import config as cf
from DISClib.ADT import list as lt
assert cf
"""
En el modelo, se crean las estructuras de datos, es decir,
las variables donde se van a guardar los datos leidos de los
archivos CSV.
El modelo debe ser el unico sitio donde se modifican y manipulan
los datos.
"""
def newCatalog():
"""
Inicializa el catálogo de libros. Crea una lista vacia para guardar
todos los libros, adicionalmente, crea una lista vacia para los autores,
una lista vacia para los generos y una lista vacia para la asociación
generos y libros. Retorna el catalogo inicializado.
"""
catalog = {
"books": None,
"tags": None,
"book_tags": None,
}
# definicion de arreglos
catalog["books"] = lt.newList(datastructure="ARRAY_LIST")
catalog["tags"] = lt.newList(datastructure="ARRAY_LIST")
catalog["book_tags"] = lt.newList(datastructure="ARRAY_LIST")
return catalog
# Funciones para agregar informacion al catalogo
def addBooks(catalog, booksfile):
"""
Para guardar los libros provenientes del archivo CSV
vamos a crear una lista, en donde quedarán todos los datos.
No es importante entender como funciona esta lista por ahora.
La funcion newList crea una lista de muchas formas. Una de ellas
es leyendo todo lo que encuentre en el archivo indicado por filename.
Cada linea del archivo quedará en una posicion de la lista.
"""
books = catalog.get("books")
books = lt.newList(datastructure="SINGLE_LINKED",
filename=booksfile)
catalog.update({"books": books})
return catalog
def addTag(catalog, tag):
"""
Para procesar el archivo de tags vamos a usar de otra forma la lista.
En este caso, agregaremos cada linea del archivo a la lista, en lugar
de usar la opcion de crearla con el nombre del archivo.
"""
tags = catalog.get("tags")
lt.addLast(tags, tag)
return catalog
def createTagList(catalog):
"""
Esta funcion crea una lista vacia. Esta lista se utilizara
para ir guardando la informacion en el archivo de tags.
"""
tags = lt.newList(datastructure="SINGLE_LINKED")
catalog.update({"tags": tags})
return catalog
def addBookTags(catalog, booktagsfile):
"""
Esta funcion crea una lista basado en el archivo de booktags. siga
el mismo procedimiento que la funcion addBooks.
"""
# TODO: Mods Lab 1, completar funcion.
pass
# Funciones de consulta
def bookSize(catalog):
return lt.size(catalog["books"])
def tagSize(catalog):
return lt.size(catalog["tags"])
def bookTagSize(catalog):
return lt.size(catalog["book_tags"])
def emptyBooks(catalog):
books = catalog.get("books")
return lt.isEmpty(books)
def emptyTags(catalog):
tags = catalog.get("tags")
return lt.isEmpty(tags)
def emptyBookTags(catalog):
book_tags = catalog.get("book_tags")
return lt.isEmpty(book_tags)