initial commit

This commit is contained in:
Chris Cromer 2019-05-26 14:06:35 -04:00
commit 23735a66de
Signed by: cromer
GPG Key ID: 39CC813FF3C8708A
55 changed files with 3311 additions and 0 deletions

10
.gitignore vendored Normal file
View File

@ -0,0 +1,10 @@
build
*.tar.gz
*.autosave
*#*#
*.aux
*.log
*.toc
*.synctex.gz
*.out
*.pdf

11
LICENSE Normal file
View File

@ -0,0 +1,11 @@
Copyright 2019 Chris Cromer
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

28
README.md Normal file
View File

@ -0,0 +1,28 @@
# Colegio
Este proyecto es para conectar a un base de datos de Postgresql para el ramo de Base de Datos.
## Profesora
Monica Mónica Caniupán & Valeria Beratto
## Requisitos
- Vala
- Meson
- Ninja
- Gtk+-3
- Libpq
- Valadoc (opcional para compilar valadoc del proyecto)
## Compilar
meson --prefix=/usr build
cd build
ninja
## Opciones de compilación
-D valadocs=true
Esta opción va a compilar la documentación de codiǵo fuente usando valadoc
-D valadocs_dep=true
Si ambos valadocs y esta opción están en uso se va a compilar la documentación del proyecto y tambien la documentación de todos los dependencias. Esta opción es caro y hace mucho mas lento la compilación.
-D debugging=true
Compilar con flags de depuración. Eso implica errores fatales que generan core dumps para ayudar con la depuración.

1
data/meson.build Normal file
View File

@ -0,0 +1 @@
subdir('ui')

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2019 Chris Cromer
~
~ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
~
~ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
~
~ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
~
~ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
~
~ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<gresources>
<gresource prefix="/cl/cromer/ubb/colegio">
<file preprocess="xml-stripblanks">main.window.ui</file>
<file preprocess="xml-stripblanks">main.splash.ui</file>
<file preprocess="to-pixdata">pixdata/icon-colegio.png</file>
<file preprocess="to-pixdata">pixdata/logo-colegio.png</file>
</gresource>
</gresources>

55
data/ui/main.splash.ui Normal file
View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1
Copyright 2019 Chris Cromer
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<interface domain="colegio">
<requires lib="gtk+" version="3.20"/>
<object class="GtkGrid" id="content_grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="column_homogeneous">True</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">end</property>
<property name="resource">/cl/cromer/ubb/colegio/pixdata/logo-colegio.png</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="label" translatable="yes">Christopher Cromer</property>
<property name="justify">center</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
</interface>

165
data/ui/main.window.ui Normal file
View File

@ -0,0 +1,165 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1
Copyright 2019 Chris Cromer
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<interface domain="colegio">
<requires lib="gtk+" version="3.20"/>
<template class="ColegioMainWindow" parent="GtkApplicationWindow">
<property name="can_focus">False</property>
<property name="title">Hogwarts School of Witchcraft and Wizardry</property>
<property name="window_position">center</property>
<signal name="destroy" handler="on_destroy" swapped="no"/>
<child>
<placeholder/>
</child>
<child>
<object class="GtkBox" id="mainbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="baseline_position">top</property>
<child>
<object class="GtkMenuBar" id="menubar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Menu</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuItem" id="tours">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Tours</property>
<signal name="activate" handler="on_activate_menu" swapped="no"/>
</object>
</child>
<child>
<object class="GtkMenuItem" id="staff">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Staff</property>
<signal name="activate" handler="on_activate_menu" swapped="no"/>
</object>
</child>
<child>
<object class="GtkMenuItem" id="tourists">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Tourists</property>
<signal name="activate" handler="on_activate_menu" swapped="no"/>
</object>
</child>
<child>
<object class="GtkSeparatorMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="quit">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Quit</property>
<signal name="activate" handler="on_activate_menu" swapped="no"/>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Views</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuItem" id="q1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">(Q1) Alumnos de Bı́obio o Ñuble</property>
<signal name="activate" handler="on_activate_menu" swapped="no"/>
</object>
</child>
<child>
<object class="GtkMenuItem" id="q2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">(Q2) Profesores sin actividad</property>
<signal name="activate" handler="on_activate_menu" swapped="no"/>
</object>
</child>
<child>
<object class="GtkMenuItem" id="q3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">(Q3) Actividades</property>
<signal name="activate" handler="on_activate_menu" swapped="no"/>
</object>
</child>
<child>
<object class="GtkMenuItem" id="q4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">(Q4) Cursos con menor matriculados</property>
<signal name="activate" handler="on_activate_menu" swapped="no"/>
</object>
</child>
<child>
<object class="GtkMenuItem" id="q5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">(Q5) Notas de asignaturas</property>
<signal name="activate" handler="on_activate_menu" swapped="no"/>
</object>
</child>
<child>
<object class="GtkMenuItem" id="q6">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">(Q6) Asignaturas con bajo aprobación</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_activate_menu" swapped="no"/>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</template>
</interface>

13
data/ui/meson.build Normal file
View File

@ -0,0 +1,13 @@
gnome = import('gnome')
main_gresource = gnome.compile_resources('main_gresource',
'main.gresource.xml',
source_dir: '.',
c_name: meson.project_name() + '_resource_main',
export: true,
install_header: true)
query_gresource = gnome.compile_resources('query_gresource',
'query.gresource.xml',
source_dir: '.',
c_name: meson.project_name() + '_resource_query',
export: true,
install_header: true)

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 KiB

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2019 Chris Cromer
~
~ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
~
~ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
~
~ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
~
~ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
~
~ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<gresources>
<gresource prefix="/cl/cromer/ubb/colegio">
<file preprocess="xml-stripblanks">query.window.ui</file>
<file preprocess="xml-stripblanks">query.tree.ui</file>
</gresource>
</gresources>

284
data/ui/query.tree.ui Normal file
View File

@ -0,0 +1,284 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1
Copyright 2019 Chris Cromer
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<interface domain="colegio">
<requires lib="gtk+" version="3.20"/>
<object class="GtkListStore" id="liststore1"/>
<object class="GtkTreeView" id="query_tree_q1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="model">liststore1</property>
<property name="headers_clickable">False</property>
<property name="enable_search">False</property>
<property name="fixed_height_mode">True</property>
<property name="show_expanders">False</property>
<property name="enable_grid_lines">both</property>
<property name="enable_tree_lines">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection">
<property name="mode">none</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="alumno">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Alumno</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="apoderado">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Apoderado</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">1</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="curso_q1">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Curso</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">2</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="jefe">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Jefe</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">3</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="asistente">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Asistente</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">4</attribute>
</attributes>
</child>
</object>
</child>
</object>
<object class="GtkTreeView" id="query_tree_q2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">liststore1</property>
<property name="headers_clickable">False</property>
<property name="enable_search">False</property>
<property name="fixed_height_mode">True</property>
<property name="show_expanders">False</property>
<property name="enable_grid_lines">both</property>
<property name="enable_tree_lines">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection">
<property name="mode">none</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="profesor">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Profesor</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">0</attribute>
</attributes>
</child>
</object>
</child>
</object>
<object class="GtkTreeView" id="query_tree_q3">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">liststore1</property>
<property name="headers_clickable">False</property>
<property name="enable_search">False</property>
<property name="fixed_height_mode">True</property>
<property name="show_expanders">False</property>
<property name="enable_grid_lines">both</property>
<property name="enable_tree_lines">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection">
<property name="mode">none</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="nombre_q3">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Nombre</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="cantidad_q3">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Cantidad</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
<object class="GtkTreeView" id="query_tree_q4">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">liststore1</property>
<property name="headers_clickable">False</property>
<property name="enable_search">False</property>
<property name="fixed_height_mode">True</property>
<property name="show_expanders">False</property>
<property name="enable_grid_lines">both</property>
<property name="enable_tree_lines">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection">
<property name="mode">none</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="curso_q4">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Curso</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="cantidad_q4">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Cantidad</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
<object class="GtkTreeView" id="query_tree_q5">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">liststore1</property>
<property name="headers_clickable">False</property>
<property name="enable_search">False</property>
<property name="fixed_height_mode">True</property>
<property name="show_expanders">False</property>
<property name="enable_grid_lines">both</property>
<property name="enable_tree_lines">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection">
<property name="mode">none</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="nombre_q5">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Nombre</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="promedio">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Promedio</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
<object class="GtkTreeView" id="query_tree_q6">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">liststore1</property>
<property name="headers_clickable">False</property>
<property name="enable_search">False</property>
<property name="fixed_height_mode">True</property>
<property name="show_expanders">False</property>
<property name="enable_grid_lines">both</property>
<property name="enable_tree_lines">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="nombre_q6">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Nombre</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Porcentaje</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
</interface>

243
data/ui/query.window.ui Normal file
View File

@ -0,0 +1,243 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1
Copyright 2019 Chris Cromer
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<interface domain="colegio">
<requires lib="gtk+" version="3.20"/>
<template class="ColegioQueryWindow" parent="GtkApplicationWindow">
<property name="can_focus">False</property>
<property name="type">popup</property>
<property name="modal">True</property>
<property name="window_position">center-on-parent</property>
<property name="default_width">800</property>
<property name="default_height">600</property>
<property name="destroy_with_parent">True</property>
<property name="type_hint">dialog</property>
<property name="skip_taskbar_hint">True</property>
<property name="skip_pager_hint">True</property>
<property name="show_menubar">False</property>
<child type="titlebar">
<placeholder/>
</child>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<child>
<object class="GtkScrolledWindow" id="scroll_window">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">center</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="hscrollbar_policy">never</property>
<property name="shadow_type">in</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="hexpand">True</property>
<property name="spacing">25</property>
<child>
<object class="GtkButton" id="close_query">
<property name="label" translatable="yes">Close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<signal name="clicked" handler="on_clicked_button" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="run_query">
<property name="label" translatable="yes">Run</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<signal name="clicked" handler="on_clicked_button" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="label_yalign">0</property>
<property name="shadow_type">out</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="label" translatable="yes">Statement</property>
<attributes>
<attribute name="font-desc" value="Sans Bold 6"/>
</attributes>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="label_yalign">0</property>
<property name="shadow_type">out</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="label" translatable="yes">View and Query</property>
<attributes>
<attribute name="font-desc" value="Sans Bold 6"/>
</attributes>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="label_xalign">0</property>
<property name="label_yalign">0</property>
<property name="shadow_type">out</property>
<child>
<object class="GtkLabel" id="statement">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="wrap">True</property>
<attributes>
<attribute name="font-desc" value="Sans 6"/>
</attributes>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="label_xalign">0</property>
<property name="label_yalign">0</property>
<property name="shadow_type">out</property>
<child>
<object class="GtkLabel" id="sql">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<attributes>
<attribute name="font-desc" value="Monospace 6"/>
</attributes>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
</child>
</template>
</interface>

191
doc/Informe/e1/Informe1.tex Normal file
View File

@ -0,0 +1,191 @@
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{array}
\usepackage{adjustbox}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm,a4paper]{geometry}
\usepackage{amsmath}
\usepackage{verbatim}
\usepackage{courier}
\usepackage{listings}
\usepackage{xcolor}
\lstdefinestyle{freefempp}{
language=SQL,
basicstyle=\footnotesize\ttfamily,
commentstyle=\itshape\color{gray},
keywordstyle=\color{blue},
numberstyle=\color{red},
stringstyle=\color{red},
identifierstyle=\color{violet},
showstringspaces=false,
%float,
%frame=single,
%numbers=left
}
\lstset{
basicstyle=\footnotesize\ttfamily,
columns=flexible,
breaklines=true,
style=freefempp
}
\usepackage{titling}
\renewcommand\maketitlehooka{\null\mbox{}\vfill}
\renewcommand\maketitlehookd{\vfill\null}
\usepackage{hyperref}
\hypersetup{colorlinks=true,allcolors=black}
\usepackage{hypcap}
\title{\textbf{Proyecto Semestral de Base de Datos\\Entrega 1}}
\author{Christopher Cromer\\\\Profesoras Mónica Caniupán y Valeria Beratto\\Ingeniería Civil Informática}
\date{\today}
\pretitle{%
\begin{center}
\LARGE
\includegraphics[width=4cm]{ubblogo.png}\\[\bigskipamount]
}
\posttitle{\end{center}}
\begin{document}
\clearpage
\hypersetup{pageanchor=false}
\begin{titlingpage}
\maketitle
\end{titlingpage}
\thispagestyle{empty}
\newpage
\clearpage
\thispagestyle{empty}
\tableofcontents
\newpage
\hypersetup{pageanchor=true}
\pagenumbering{arabic}
\section{Introducción}
El objetivo de este trabajo es modelar un sistema para los colegios municipales de la región del Bío-Bío con el propósito de almacenar y consultar en una base de datos de PostgreSQL con información el colegio.
\newpage
\section{Modelo Entidad Relación}
\begin{center}
\includegraphics[angle=270,origin=c,width=0.90\textwidth,height=0.90\textheight,keepaspectratio]{MER.png}
\end{center}
\newpage
\section{Modelo Relacional}
\begin{center}
En negrita se presentan las claves foráneas y las primarias en subrayado.\smallskip
\end{center}
region(\underline{id\_region}, nombre)\bigskip
\noindent
ciudad(\underline{id\_ciudad}, nombre, \textbf{id\_region})\bigskip
\noindent
apoderado(\underline{rut\_apoderado}, nombres, apellidos, direccion, \textbf{id\_ciudad})\bigskip
\noindent
alumno(\underline{rut\_alumno}, nombres, apellidos, direccion, \textbf{id\_ciudad}, anyo\_ingreso, fecha\_nacimiento, \textbf{rut\_apoderado})\bigskip
\noindent
profesor(\underline{rut\_profesor}, nombres, apellidos, direccion, \textbf{id\_ciudad})\bigskip
\noindent
actividad(\underline{id\_actividad}, nombre, cupos, lugar, \textbf{rut\_profesor})\bigskip
\noindent
nivel(\underline{id\_nivel}, nombre)\bigskip
\noindent
bloque(\underline{id\_bloque}, descripcion)\bigskip
\noindent
curso(\underline{id\_curso}, \textbf{rut\_profesor})\bigskip
\noindent
asignatura(\underline{id\_asignatura}, nombre, \textbf{rut\_profesor})\bigskip
\noindent
participar(\textbf{\underline{rut\_alumno}}, \textbf{\underline{id\_actividad}})\bigskip
\noindent
actividad\_nivel(\textbf{\underline{id\_actividad}}, \textbf{\underline{id\_nivel}})\bigskip
\noindent
actividad\_bloque(\textbf{\underline{id\_actividad}}, \textbf{\underline{id\_bloque}})\bigskip
\noindent
horario(\textbf{\underline{id\_asignatura}}, \textbf{\underline{id\_bloque}}, sala)\bigskip
\noindent
registro(\textbf{\underline{rut\_alumno}}, \textbf{\underline{id\_asignatura}}, nota)\bigskip
\noindent
cursar(\textbf{\underline{rut\_alumno}}, \textbf{\underline{id\_curso}})\bigskip
\noindent
asociado(\textbf{\underline{id\_curso}}, \textbf{\underline{id\_asignatura}})\bigskip
\noindent
asistente(\textbf{\underline{rut\_profesor}}, \textbf{\underline{id\_curso}})\bigskip
\newpage
\section{Justificación de Modelo Relacional}
\textbf{\textit{region}} no adquiere ninguna clave foránea debido a que las relaciones entre las otras entidades son de \textbf{\textit{1 a n}}.\bigskip
\textbf{\textit{ciudad}} adquiere la clave foránea \textbf{\textit{id\_region}} debido a que la relación entre las entidades \textbf{\textit{ciudad}} y \textbf{\textit{region}} es de \textbf{\textit{n a 1}}.\bigskip
\textbf{\textit{apoderado}} adquiere la clave foránea \textbf{\textit{id\_ciudad}} debido a que la relación entre las entidades \textbf{\textit{apoderado}} y \textbf{\textit{ciudad}} es de \textbf{\textit{n a 1}}.\bigskip
\textbf{\textit{alumno}} adquiere la clave foránea \textbf{\textit{id\_ciudad}} debido a que la relación entre las entidades \textbf{\textit{alumno}} y \textbf{\textit{ciudad}} es de \textbf{\textit{n a 1}}. También recibe la clave foránea \textbf{rut\_apoderado} debido a la relación entre las entidades \textbf{alumno} y \textbf{apoderado} que es de \textbf{n a 1}.\bigskip
\textbf{\textit{profesor}} adquiere la clave foránea \textbf{\textit{id\_ciudad}} debido a que la relación entre las entidades \textbf{\textit{profesor}} y \textbf{\textit{ciudad}} es de \textbf{\textit{n a 1}}.\bigskip
\textbf{\textit{actividad}} adquiere la clave foránea \textbf{\textit{rut\_profesor}} debido a que las relaciones entre las otras entidades \textbf{\textit{actividad}} y \textbf{\textit{profesor}} es de \textbf{\textit{1 a n}}.\bigskip
\textbf{\textit{nivel}} no adquiere ninguna clave foránea debido a que las relaciones entre las otras entidades son de \textbf{\textit{1 a n}}.\bigskip
\textbf{\textit{bloque}} no adquiere ninguna clave foránea debido a que las relaciones entre las otras entidades son de \textbf{\textit{1 a n}}.\bigskip
\textbf{\textit{curso}} adquiere la clave foránea \textbf{\textit{rut}} debido a que las relaciones entre las entidades \textbf{\textit{curso}} y \textbf{\textit{profesor}} es de \textbf{\textit{n a 1}}.\bigskip
\textbf{\textit{asignatura}} adquiere la clave foránea \textbf{\textit{rut\_profesor}} debido a que la relación entre las entidades \textbf{\textit{asignatura}} y \textbf{\textit{profesor}} es de \textbf{\textit{n a 1}}.\bigskip
\textbf{\textit{participar}} es creado con las claves foráneas \textbf{\textit{rut\_alumno}} y \textbf{\textit{id\_actividad}} dado que la relación entre \textbf{\textit{alumno}} y \textbf{\textit{actividad}} es de \textbf{\textit{n a n}}.\bigskip
\textbf{\textit{actividad\_nivel}} es creado con las claves foráneas \textbf{\textit{id\_actividad}} y \textbf{\textit{id\_nivel}} dado que la relación entre \textbf{\textit{actividad}} y \textbf{\textit{nivel}} es de \textbf{\textit{n a n}}.\bigskip
\textbf{\textit{actividad\_bloque}} es creado con las claves foráneas \textbf{\textit{id\_actividad}} y \textbf{\textit{id\_bloque}} dado que la relación entre \textbf{\textit{actividad}} y \textbf{\textit{bloque}} es de \textbf{\textit{n a n}}.\bigskip
\textbf{\textit{horario}} es creado con las claves foráneas \textbf{\textit{id\_asignatura}} y \textbf{\textit{id\_bloque}}, y queda con el atributo \textbf{\textit{sala}} dado que la relación entre \textbf{\textit{asignatura}} y \textbf{\textit{bloque}} es de \textbf{\textit{n a n}}.\bigskip
\textbf{\textit{registro}} es creado con las claves foráneas \textbf{\textit{rut\_alumno}} y \textbf{\textit{id\_asignatura}}, y queda con el atributo \textbf{\textit{nota}} dado que la relación entre \textbf{\textit{alumno}} y \textbf{\textit{asignatura}} es de \textbf{\textit{n a n}}.\bigskip
\textbf{\textit{cursar}} es creado con las claves foráneas \textbf{\textit{rut\_alumno}} y \textbf{\textit{id\_curso}} dado que la relación entre \textbf{\textit{alumno}} y \textbf{\textit{curso}} es de \textbf{\textit{n a n}}.\bigskip
\textbf{\textit{asociado}} es creado con las claves foráneas \textbf{\textit{id\_curso}} y \textbf{\textit{id\_asignatura}} dado que la relación entre \textbf{\textit{curso}} y \textbf{\textit{asignatura}} es de \textbf{\textit{n a n}}.\bigskip
\textbf{\textit{asistente}} es creado opcionalmente con las claves foráneas \textbf{\textit{rut\_profesor}} y \textbf{\textit{id\_curso}} dado que la relación entre \textbf{\textit{curso}} y \textbf{\textit{profesor}} es de \textbf{\textit{n a 1 con mínimo de 0}}.\bigskip
\newpage
\section{Script SQL}
\subsection{Crear tablas}
\lstinputlisting{crear_tablas.sql}
\newpage
\subsection{Insertar duplas}
\lstinputlisting{insertar_duplas.sql}
\end{document}

BIN
doc/Informe/e1/MER.dia Normal file

Binary file not shown.

BIN
doc/Informe/e1/MER.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

View File

@ -0,0 +1,150 @@
CREATE TABLE region(
id_region SMALLSERIAL UNIQUE,
nombre_region VARCHAR(20) NOT NULL,
PRIMARY KEY (id_region)
);
CREATE TABLE ciudad(
id_ciudad SMALLSERIAL UNIQUE,
nombre_ciudad VARCHAR(20) NOT NULL,
id_region SMALLINT,
PRIMARY KEY (id_ciudad),
FOREIGN KEY (id_region) REFERENCES region (id_region) ON DELETE RESTRICT
);
CREATE TABLE apoderado(
rut_apoderado VARCHAR(9) NOT NULL UNIQUE CHECK (rut_apoderado ~ '^[0-9k]+$'),
nombres VARCHAR(50) NOT NULL,
apellidos VARCHAR(50) NOT NULL,
direccion VARCHAR(30) NOT NULL,
id_ciudad SMALLINT,
PRIMARY KEY (rut_apoderado),
FOREIGN KEY (id_ciudad) REFERENCES ciudad (id_ciudad) ON DELETE RESTRICT
);
CREATE TABLE alumno(
rut_alumno VARCHAR(9) NOT NULL UNIQUE CHECK (rut_alumno ~ '^[0-9k]+$'),
nombres VARCHAR(50) NOT NULL,
apellidos VARCHAR(50) NOT NULL,
direccion VARCHAR(30) NOT NULL,
id_ciudad SMALLINT,
anyo_ingreso SMALLINT CHECK (anyo_ingreso > 1980),
fecha_nacimiento DATE NOT NULL CHECK (fecha_nacimiento > '1980-01-01'),
rut_apoderado VARCHAR(9) NOT NULL CHECK (rut_apoderado ~ '^[0-9k]+$'),
PRIMARY KEY (rut_alumno),
FOREIGN KEY (id_ciudad) REFERENCES ciudad (id_ciudad) ON DELETE RESTRICT,
FOREIGN KEY (rut_apoderado) REFERENCES apoderado (rut_apoderado) ON DELETE RESTRICT
);
CREATE TABLE profesor(
rut_profesor VARCHAR(9) NOT NULL UNIQUE CHECK (rut_profesor ~ '^[0-9k]+$'),
nombres VARCHAR(50) NOT NULL,
apellidos VARCHAR(50) NOT NULL,
direccion VARCHAR(30) NOT NULL,
id_ciudad SMALLINT,
PRIMARY KEY (rut_profesor),
FOREIGN KEY (id_ciudad) REFERENCES ciudad (id_ciudad) ON DELETE RESTRICT
);
CREATE TABLE actividad(
id_actividad SERIAL UNIQUE,
nombre VARCHAR(50) NOT NULL,
cupos SMALLINT CHECK (cupos > 0),
lugar VARCHAR(20) NOT NULL,
rut_profesor VARCHAR(9) NOT NULL UNIQUE CHECK (rut_profesor ~ '^[0-9k]+$'),
PRIMARY KEY (id_actividad),
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT
);
CREATE TABLE nivel(
id_nivel SERIAL UNIQUE,
nombre VARCHAR(20) NOT NULL,
PRIMARY KEY (id_nivel)
);
CREATE TABLE bloque(
id_bloque SERIAL UNIQUE,
descripcion VARCHAR(20) NOT NULL,
PRIMARY KEY (id_bloque)
);
CREATE TABLE curso(
id_curso VARCHAR(10) NOT NULL UNIQUE,
rut_profesor VARCHAR(9) NOT NULL CHECK (rut_profesor ~ '^[0-9k]+$'),
PRIMARY KEY (id_curso),
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT
);
CREATE TABLE asignatura(
id_asignatura SERIAL UNIQUE,
nombre VARCHAR(50) NOT NULL,
rut_profesor VARCHAR(9) NOT NULL CHECK (rut_profesor ~ '^[0-9k]+$'),
PRIMARY KEY (id_asignatura),
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT
);
CREATE TABLE participar(
rut_alumno VARCHAR(9) NOT NULL CHECK (rut_alumno ~ '^[0-9k]+$'),
id_actividad INT,
PRIMARY KEY (rut_alumno, id_actividad),
FOREIGN KEY (rut_alumno) REFERENCES alumno (rut_alumno) ON DELETE RESTRICT,
FOREIGN KEY (id_actividad) REFERENCES actividad (id_actividad) ON DELETE RESTRICT
);
CREATE TABLE actividad_nivel(
id_actividad INT,
id_nivel INT,
PRIMARY KEY (id_actividad, id_nivel),
FOREIGN KEY (id_actividad) REFERENCES actividad (id_actividad) ON DELETE RESTRICT,
FOREIGN KEY (id_nivel) REFERENCES nivel (id_nivel) ON DELETE RESTRICT
);
CREATE TABLE actividad_bloque(
id_actividad INT,
id_bloque INT,
PRIMARY KEY (id_actividad, id_bloque),
FOREIGN KEY (id_actividad) REFERENCES actividad (id_actividad) ON DELETE RESTRICT,
FOREIGN KEY (id_bloque) REFERENCES bloque (id_bloque) ON DELETE RESTRICT
);
CREATE TABLE horario(
id_asignatura INT,
id_bloque INT,
sala VARCHAR(20) NOT NULL,
PRIMARY KEY (id_asignatura, id_bloque),
FOREIGN KEY (id_asignatura) REFERENCES asignatura (id_asignatura) ON DELETE RESTRICT,
FOREIGN KEY (id_bloque) REFERENCES bloque (id_bloque) ON DELETE RESTRICT
);
CREATE TABLE registro(
rut_alumno VARCHAR(9) NOT NULL CHECK (rut_alumno ~ '^[0-9k]+$'),
id_asignatura INT,
nota NUMERIC(2,1) CHECK (nota >= 1.0 AND nota <= 7.0),
PRIMARY KEY (rut_alumno, id_asignatura),
FOREIGN KEY (rut_alumno) REFERENCES alumno (rut_alumno) ON DELETE RESTRICT,
FOREIGN KEY (id_asignatura) REFERENCES asignatura (id_asignatura) ON DELETE RESTRICT
);
CREATE TABLE cursar(
rut_alumno VARCHAR(9) NOT NULL CHECK (rut_alumno ~ '^[0-9k]+$'),
id_curso VARCHAR(10) NOT NULL,
PRIMARY KEY (rut_alumno, id_curso),
FOREIGN KEY (rut_alumno) REFERENCES alumno (rut_alumno) ON DELETE RESTRICT,
FOREIGN KEY (id_curso) REFERENCES curso (id_curso) ON DELETE RESTRICT
);
CREATE TABLE asociado(
id_curso VARCHAR(10) NOT NULL,
id_asignatura INT,
PRIMARY KEY (id_curso, id_asignatura),
FOREIGN KEY (id_curso) REFERENCES curso (id_curso) ON DELETE RESTRICT,
FOREIGN KEY (id_asignatura) REFERENCES asignatura (id_asignatura) ON DELETE RESTRICT
);
CREATE TABLE asistente(
rut_profesor VARCHAR(9) NOT NULL CHECK (rut_profesor ~ '^[0-9k]+$'),
id_curso VARCHAR(10) NOT NULL,
PRIMARY KEY (rut_profesor, id_curso),
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT,
FOREIGN KEY (id_curso) REFERENCES curso (id_curso) ON DELETE RESTRICT
);

View File

@ -0,0 +1,71 @@
INSERT INTO region (id_region, nombre_region) VALUES (1, 'Florida');
INSERT INTO region (id_region, nombre_region) VALUES (2, 'Alabama');
INSERT INTO region (id_region, nombre_region) VALUES (3, 'Virginia');
INSERT INTO ciudad (id_ciudad, nombre_ciudad, id_region) VALUES (1, 'Pensacola', 1);
INSERT INTO ciudad (id_ciudad, nombre_ciudad, id_region) VALUES (2, 'Montgomery', 2);
INSERT INTO ciudad (id_ciudad, nombre_ciudad, id_region) VALUES (3, 'Virginia Beach', 3);
INSERT INTO apoderado (rut_apoderado, nombres, apellidos, direccion, id_ciudad) VALUES ('14592927k', 'Christopher Barry', 'Cromer', '214 Edison Dr.', 1);
INSERT INTO apoderado (rut_apoderado, nombres, apellidos, direccion, id_ciudad) VALUES ('192186099', 'Elia Alejandra', 'Chacano Troncoso', 'Avenida San Sebastian 778', 2);
INSERT INTO apoderado (rut_apoderado, nombres, apellidos, direccion, id_ciudad) VALUES ('192199859', 'Jack', 'Johnson', '320 Thomas Jefferson St.', 3);
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('254049492', 'Izabella Lynn', 'Cromer Chacano', '214 Edison Dr.', 2019, '2019-10-04', '14592927k', 1);
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('245191391', 'Tomas', 'Bunt', 'Avenida San Sebastian 778', 2018, '2010-02-05', '192186099', 2);
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('18028642k', 'Tom', 'Riddle', '320 Thomas Jefferson St.', 2017, '2014-12-31', '192199859', 3);
INSERT INTO profesor (rut_profesor, nombres, apellidos, direccion, id_ciudad) VALUES ('226174788', 'Severus', 'Snape', '232 Jackson Ave.', 1);
INSERT INTO profesor (rut_profesor, nombres, apellidos, direccion, id_ciudad) VALUES ('226779329', 'Minerva', 'McGonagall', '333 Nottingham Ln.', 2);
INSERT INTO profesor (rut_profesor, nombres, apellidos, direccion, id_ciudad) VALUES ('139414853', 'Albus', 'Dumbledore', '8450 Sparrow Rd.', 3);
INSERT INTO actividad (id_actividad, nombre, cupos, lugar, rut_profesor) VALUES (1, 'Quidditch', 14, 'Quidditch field', '226174788');
INSERT INTO actividad (id_actividad, nombre, cupos, lugar, rut_profesor) VALUES (2, 'Ogre taming', 5, 'The forbidden forest', '226779329');
INSERT INTO actividad (id_actividad, nombre, cupos, lugar, rut_profesor) VALUES (3, 'Advanced transfiguration', 2, 'Headmaster''s office', '139414853');
INSERT INTO nivel (id_nivel, nombre) VALUES (1, 'First');
INSERT INTO nivel (id_nivel, nombre) VALUES (2, 'Second');
INSERT INTO nivel (id_nivel, nombre) VALUES (3, 'Third');
INSERT INTO bloque (id_bloque, descripcion) VALUES (1, '08:10 - 09:30');
INSERT INTO bloque (id_bloque, descripcion) VALUES (2, '09:40 - 11:00');
INSERT INTO bloque (id_bloque, descripcion) VALUES (3, '11:10 - 12:30');
INSERT INTO curso (id_curso, rut_profesor) VALUES ('1A-2017', '226174788');
INSERT INTO curso (id_curso, rut_profesor) VALUES ('2B-2018', '226779329');
INSERT INTO curso (id_curso, rut_profesor) VALUES ('3C-2019', '139414853');
INSERT INTO asignatura (id_asignatura, nombre, rut_profesor) VALUES (1, 'Transfiguration', '226779329');
INSERT INTO asignatura (id_asignatura, nombre, rut_profesor) VALUES (2, 'Defense against the dark arts', '226174788');
INSERT INTO asignatura (id_asignatura, nombre, rut_profesor) VALUES (3, 'Muggle studies', '139414853');
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('254049492', 1);
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('245191391', 2);
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('18028642k', 3);
INSERT INTO actividad_nivel (id_actividad, id_nivel) VALUES (1, 1);
INSERT INTO actividad_nivel (id_actividad, id_nivel) VALUES (2, 2);
INSERT INTO actividad_nivel (id_actividad, id_nivel) VALUES (3, 3);
INSERT INTO actividad_bloque (id_actividad, id_bloque) VALUES (1, 1);
INSERT INTO actividad_bloque (id_actividad, id_bloque) VALUES (2, 2);
INSERT INTO actividad_bloque (id_actividad, id_bloque) VALUES (3, 3);
INSERT INTO horario (id_asignatura, id_bloque, sala) VALUES (1, 1, '203AC');
INSERT INTO horario (id_asignatura, id_bloque, sala) VALUES (2, 2, '301AB');
INSERT INTO horario (id_asignatura, id_bloque, sala) VALUES (3, 3, '102AA');
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('254049492', 1, 7.0);
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('245191391', 2, 4.0);
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('18028642k', 3, 1.0);
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('254049492', '1A-2017');
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('245191391', '2B-2018');
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('18028642k', '3C-2019');
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('1A-2017', 1);
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('2B-2018', 2);
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('3C-2019', 3);
INSERT INTO asistente (rut_profesor, id_curso) VALUES ('139414853', '1A-2017');
INSERT INTO asistente (rut_profesor, id_curso) VALUES ('226174788', '2B-2018');
INSERT INTO asistente (rut_profesor, id_curso) VALUES ('226779329', '3C-2019');

BIN
doc/Informe/e1/ubblogo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

View File

@ -0,0 +1,194 @@
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{array}
\usepackage{adjustbox}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm,a4paper]{geometry}
\usepackage{amsmath}
\usepackage{verbatim}
\usepackage{courier}
\usepackage{listings}
\usepackage{xcolor}
\lstdefinestyle{freefempp}{
language=SQL,
basicstyle=\footnotesize\ttfamily,
commentstyle=\itshape\color{gray},
keywordstyle=\color{blue},
numberstyle=\color{red},
stringstyle=\color{red},
identifierstyle=\color{violet},
showstringspaces=false,
%float,
%frame=single,
%numbers=left
}
\lstset{
basicstyle=\footnotesize\ttfamily,
columns=flexible,
breaklines=true,
inputencoding=utf8,
extendedchars=true,
literate={á}{{\'a}}1 {é}{{\'e}}1 {í}{{\'i}}1 {ó}{{\'o}}1 {ú}{{\'u}}1 {ñ}{{\~n}}1 {Á}{{\'A}}1 {É}{{\'E}}1 {Í}{{\'I}}1 {Ó}{{\'O}}1 {Ú}{{\'U}}1 {Ñ}{{\~N}}1,
style=freefempp
}
\usepackage{titling}
\renewcommand\maketitlehooka{\null\mbox{}\vfill}
\renewcommand\maketitlehookd{\vfill\null}
\usepackage{hyperref}
\hypersetup{colorlinks=true,allcolors=black}
\usepackage{hypcap}
\title{\textbf{Proyecto Semestral de Base de Datos\\Entrega 1 Corregido}}
\author{Christopher Cromer\\\\Profesoras Mónica Caniupán y Valeria Beratto\\Ingeniería Civil Informática}
\date{\today}
\pretitle{%
\begin{center}
\LARGE
\includegraphics[width=4cm]{ubblogo.png}\\[\bigskipamount]
}
\posttitle{\end{center}}
\begin{document}
\clearpage
\hypersetup{pageanchor=false}
\begin{titlingpage}
\maketitle
\end{titlingpage}
\thispagestyle{empty}
\newpage
\clearpage
\thispagestyle{empty}
\tableofcontents
\newpage
\hypersetup{pageanchor=true}
\pagenumbering{arabic}
\section{Introducción}
El objetivo de este trabajo es modelar un sistema para los colegios municipales de la región del Bío-Bío con el propósito de almacenar y consultar en una base de datos de PostgreSQL con información el colegio.
\newpage
\section{Modelo Entidad Relación}
\begin{center}
\includegraphics[angle=270,origin=c,width=0.90\textwidth,height=0.90\textheight,keepaspectratio]{MER.png}
\end{center}
\newpage
\section{Modelo Relacional}
\begin{center}
En negrita se presentan las claves foráneas y las primarias en subrayado.\smallskip
\end{center}
region(\underline{id\_region}, nombre)\bigskip
\noindent
ciudad(\underline{id\_ciudad}, nombre, \textbf{id\_region})\bigskip
\noindent
apoderado(\underline{rut\_apoderado}, nombres, apellidos, direccion, \textbf{id\_ciudad})\bigskip
\noindent
alumno(\underline{rut\_alumno}, nombres, apellidos, direccion, \textbf{id\_ciudad}, anyo\_ingreso, fecha\_nacimiento, \textbf{rut\_apoderado})\bigskip
\noindent
profesor(\underline{rut\_profesor}, nombres, apellidos, direccion, \textbf{id\_ciudad})\bigskip
\noindent
actividad(\underline{id\_actividad}, nombre, cupos, lugar, \textbf{rut\_profesor})\bigskip
\noindent
nivel(\underline{id\_nivel}, nombre)\bigskip
\noindent
bloque(\underline{id\_bloque}, descripcion)\bigskip
\noindent
curso(\underline{id\_curso}, nombre, anyo, \textbf{rut\_profesor})\bigskip
\noindent
asignatura(\underline{id\_asignatura}, nombre, \textbf{rut\_profesor})\bigskip
\noindent
participar(\textbf{\underline{rut\_alumno}}, \textbf{\underline{id\_actividad}})\bigskip
\noindent
actividad\_nivel(\textbf{\underline{id\_actividad}}, \textbf{\underline{id\_nivel}})\bigskip
\noindent
actividad\_bloque(\textbf{\underline{id\_actividad}}, \textbf{\underline{id\_bloque}})\bigskip
\noindent
horario(\textbf{\underline{id\_asignatura}}, \textbf{\underline{id\_bloque}}, sala)\bigskip
\noindent
registro(\textbf{\underline{rut\_alumno}}, \textbf{\underline{id\_asignatura}}, nota)\bigskip
\noindent
cursar(\textbf{\underline{rut\_alumno}}, \textbf{\underline{id\_curso}})\bigskip
\noindent
asociado(\textbf{\underline{id\_curso}}, \textbf{\underline{id\_asignatura}})\bigskip
\noindent
asistente(\textbf{\underline{rut\_profesor}}, \textbf{\underline{id\_curso}})\bigskip
\newpage
\section{Justificación de Modelo Relacional}
\textbf{\textit{region}} no adquiere ninguna clave foránea debido a que las relaciones entre las otras entidades son de \textbf{\textit{1 a n}}.\bigskip
\textbf{\textit{ciudad}} adquiere la clave foránea \textbf{\textit{id\_region}} debido a que la relación entre las entidades \textbf{\textit{ciudad}} y \textbf{\textit{region}} es de \textbf{\textit{n a 1}}.\bigskip
\textbf{\textit{apoderado}} adquiere la clave foránea \textbf{\textit{id\_ciudad}} debido a que la relación entre las entidades \textbf{\textit{apoderado}} y \textbf{\textit{ciudad}} es de \textbf{\textit{n a 1}}.\bigskip
\textbf{\textit{alumno}} adquiere la clave foránea \textbf{\textit{id\_ciudad}} debido a que la relación entre las entidades \textbf{\textit{alumno}} y \textbf{\textit{ciudad}} es de \textbf{\textit{n a 1}}. También recibe la clave foránea \textbf{rut\_apoderado} debido a la relación entre las entidades \textbf{alumno} y \textbf{apoderado} que es de \textbf{n a 1}.\bigskip
\textbf{\textit{profesor}} adquiere la clave foránea \textbf{\textit{id\_ciudad}} debido a que la relación entre las entidades \textbf{\textit{profesor}} y \textbf{\textit{ciudad}} es de \textbf{\textit{n a 1}}.\bigskip
\textbf{\textit{actividad}} adquiere la clave foránea \textbf{\textit{rut\_profesor}} debido a que las relaciones entre las otras entidades \textbf{\textit{actividad}} y \textbf{\textit{profesor}} es de \textbf{\textit{1 a n}}.\bigskip
\textbf{\textit{nivel}} no adquiere ninguna clave foránea debido a que las relaciones entre las otras entidades son de \textbf{\textit{1 a n}}.\bigskip
\textbf{\textit{bloque}} no adquiere ninguna clave foránea debido a que las relaciones entre las otras entidades son de \textbf{\textit{1 a n}}.\bigskip
\textbf{\textit{curso}} adquiere la clave foránea \textbf{\textit{rut}} debido a que las relaciones entre las entidades \textbf{\textit{curso}} y \textbf{\textit{profesor}} es de \textbf{\textit{n a 1}}.\bigskip
\textbf{\textit{asignatura}} adquiere la clave foránea \textbf{\textit{rut\_profesor}} debido a que la relación entre las entidades \textbf{\textit{asignatura}} y \textbf{\textit{profesor}} es de \textbf{\textit{n a 1}}.\bigskip
\textbf{\textit{participar}} es creado con las claves foráneas \textbf{\textit{rut\_alumno}} y \textbf{\textit{id\_actividad}} dado que la relación entre \textbf{\textit{alumno}} y \textbf{\textit{actividad}} es de \textbf{\textit{n a n}}.\bigskip
\textbf{\textit{actividad\_nivel}} es creado con las claves foráneas \textbf{\textit{id\_actividad}} y \textbf{\textit{id\_nivel}} dado que la relación entre \textbf{\textit{actividad}} y \textbf{\textit{nivel}} es de \textbf{\textit{n a n}}.\bigskip
\textbf{\textit{actividad\_bloque}} es creado con las claves foráneas \textbf{\textit{id\_actividad}} y \textbf{\textit{id\_bloque}} dado que la relación entre \textbf{\textit{actividad}} y \textbf{\textit{bloque}} es de \textbf{\textit{n a n}}.\bigskip
\textbf{\textit{horario}} es creado con las claves foráneas \textbf{\textit{id\_asignatura}} y \textbf{\textit{id\_bloque}}, y queda con el atributo \textbf{\textit{sala}} dado que la relación entre \textbf{\textit{asignatura}} y \textbf{\textit{bloque}} es de \textbf{\textit{n a n}}.\bigskip
\textbf{\textit{registro}} es creado con las claves foráneas \textbf{\textit{rut\_alumno}} y \textbf{\textit{id\_asignatura}}, y queda con el atributo \textbf{\textit{nota}} dado que la relación entre \textbf{\textit{alumno}} y \textbf{\textit{asignatura}} es de \textbf{\textit{n a n}}.\bigskip
\textbf{\textit{cursar}} es creado con las claves foráneas \textbf{\textit{rut\_alumno}} y \textbf{\textit{id\_curso}} dado que la relación entre \textbf{\textit{alumno}} y \textbf{\textit{curso}} es de \textbf{\textit{n a n}}.\bigskip
\textbf{\textit{asociado}} es creado con las claves foráneas \textbf{\textit{id\_curso}} y \textbf{\textit{id\_asignatura}} dado que la relación entre \textbf{\textit{curso}} y \textbf{\textit{asignatura}} es de \textbf{\textit{n a n}}.\bigskip
\textbf{\textit{asistente}} es creado opcionalmente con las claves foráneas \textbf{\textit{rut\_profesor}} y \textbf{\textit{id\_curso}} dado que la relación entre \textbf{\textit{curso}} y \textbf{\textit{profesor}} es de \textbf{\textit{n a 1 con mínimo de 0}}.\bigskip
\newpage
\section{Script SQL}
\subsection{Crear tablas}
\lstinputlisting{crear_tablas.sql}
\newpage
\subsection{Insertar duplas}
\lstinputlisting{insertar_duplas.sql}
\end{document}

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

View File

@ -0,0 +1,152 @@
CREATE TABLE region(
id_region SMALLSERIAL UNIQUE,
nombre_region VARCHAR(20) NOT NULL,
PRIMARY KEY (id_region)
);
CREATE TABLE ciudad(
id_ciudad SMALLSERIAL UNIQUE,
nombre_ciudad VARCHAR(20) NOT NULL,
id_region SMALLINT,
PRIMARY KEY (id_ciudad),
FOREIGN KEY (id_region) REFERENCES region (id_region) ON DELETE RESTRICT
);
CREATE TABLE apoderado(
rut_apoderado VARCHAR(9) NOT NULL UNIQUE CHECK (rut_apoderado ~ '^[0-9k]+$'),
nombres VARCHAR(50) NOT NULL,
apellidos VARCHAR(50) NOT NULL,
direccion VARCHAR(30) NOT NULL,
id_ciudad SMALLINT,
PRIMARY KEY (rut_apoderado),
FOREIGN KEY (id_ciudad) REFERENCES ciudad (id_ciudad) ON DELETE RESTRICT
);
CREATE TABLE alumno(
rut_alumno VARCHAR(9) NOT NULL UNIQUE CHECK (rut_alumno ~ '^[0-9k]+$'),
nombres VARCHAR(50) NOT NULL,
apellidos VARCHAR(50) NOT NULL,
direccion VARCHAR(30) NOT NULL,
id_ciudad SMALLINT,
anyo_ingreso SMALLINT CHECK (anyo_ingreso > 1980),
fecha_nacimiento DATE NOT NULL CHECK (fecha_nacimiento > '1980-01-01'),
rut_apoderado VARCHAR(9) NOT NULL CHECK (rut_apoderado ~ '^[0-9k]+$'),
PRIMARY KEY (rut_alumno),
FOREIGN KEY (id_ciudad) REFERENCES ciudad (id_ciudad) ON DELETE RESTRICT,
FOREIGN KEY (rut_apoderado) REFERENCES apoderado (rut_apoderado) ON DELETE RESTRICT
);
CREATE TABLE profesor(
rut_profesor VARCHAR(9) NOT NULL UNIQUE CHECK (rut_profesor ~ '^[0-9k]+$'),
nombres VARCHAR(50) NOT NULL,
apellidos VARCHAR(50) NOT NULL,
direccion VARCHAR(30) NOT NULL,
id_ciudad SMALLINT,
PRIMARY KEY (rut_profesor),
FOREIGN KEY (id_ciudad) REFERENCES ciudad (id_ciudad) ON DELETE RESTRICT
);
CREATE TABLE actividad(
id_actividad SERIAL UNIQUE,
nombre VARCHAR(50) NOT NULL,
cupos SMALLINT CHECK (cupos > 0),
lugar VARCHAR(20) NOT NULL,
rut_profesor VARCHAR(9) NOT NULL UNIQUE CHECK (rut_profesor ~ '^[0-9k]+$'),
PRIMARY KEY (id_actividad),
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT
);
CREATE TABLE nivel(
id_nivel SERIAL UNIQUE,
nombre VARCHAR(20) NOT NULL,
PRIMARY KEY (id_nivel)
);
CREATE TABLE bloque(
id_bloque SERIAL UNIQUE,
descripcion VARCHAR(20) NOT NULL,
PRIMARY KEY (id_bloque)
);
CREATE TABLE curso(
id_curso VARCHAR(10) NOT NULL UNIQUE,
nombre VARCHAR(6) NOT NULL,
anyo SMALLINT CHECK (anyo > 1980),
rut_profesor VARCHAR(9) NOT NULL CHECK (rut_profesor ~ '^[0-9k]+$'),
PRIMARY KEY (id_curso),
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT
);
CREATE TABLE asignatura(
id_asignatura SERIAL UNIQUE,
nombre VARCHAR(50) NOT NULL,
rut_profesor VARCHAR(9) NOT NULL CHECK (rut_profesor ~ '^[0-9k]+$'),
PRIMARY KEY (id_asignatura),
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT
);
CREATE TABLE participar(
rut_alumno VARCHAR(9) NOT NULL CHECK (rut_alumno ~ '^[0-9k]+$'),
id_actividad INT,
PRIMARY KEY (rut_alumno, id_actividad),
FOREIGN KEY (rut_alumno) REFERENCES alumno (rut_alumno) ON DELETE RESTRICT,
FOREIGN KEY (id_actividad) REFERENCES actividad (id_actividad) ON DELETE RESTRICT
);
CREATE TABLE actividad_nivel(
id_actividad INT,
id_nivel INT,
PRIMARY KEY (id_actividad, id_nivel),
FOREIGN KEY (id_actividad) REFERENCES actividad (id_actividad) ON DELETE RESTRICT,
FOREIGN KEY (id_nivel) REFERENCES nivel (id_nivel) ON DELETE RESTRICT
);
CREATE TABLE actividad_bloque(
id_actividad INT,
id_bloque INT,
PRIMARY KEY (id_actividad, id_bloque),
FOREIGN KEY (id_actividad) REFERENCES actividad (id_actividad) ON DELETE RESTRICT,
FOREIGN KEY (id_bloque) REFERENCES bloque (id_bloque) ON DELETE RESTRICT
);
CREATE TABLE horario(
id_asignatura INT,
id_bloque INT,
sala VARCHAR(20) NOT NULL,
PRIMARY KEY (id_asignatura, id_bloque),
FOREIGN KEY (id_asignatura) REFERENCES asignatura (id_asignatura) ON DELETE RESTRICT,
FOREIGN KEY (id_bloque) REFERENCES bloque (id_bloque) ON DELETE RESTRICT
);
CREATE TABLE registro(
rut_alumno VARCHAR(9) NOT NULL CHECK (rut_alumno ~ '^[0-9k]+$'),
id_asignatura INT,
nota NUMERIC(2,1) CHECK (nota >= 1.0 AND nota <= 7.0),
PRIMARY KEY (rut_alumno, id_asignatura),
FOREIGN KEY (rut_alumno) REFERENCES alumno (rut_alumno) ON DELETE RESTRICT,
FOREIGN KEY (id_asignatura) REFERENCES asignatura (id_asignatura) ON DELETE RESTRICT
);
CREATE TABLE cursar(
rut_alumno VARCHAR(9) NOT NULL CHECK (rut_alumno ~ '^[0-9k]+$'),
id_curso VARCHAR(10) NOT NULL,
PRIMARY KEY (rut_alumno, id_curso),
FOREIGN KEY (rut_alumno) REFERENCES alumno (rut_alumno) ON DELETE RESTRICT,
FOREIGN KEY (id_curso) REFERENCES curso (id_curso) ON DELETE RESTRICT
);
CREATE TABLE asociado(
id_curso VARCHAR(10) NOT NULL,
id_asignatura INT,
PRIMARY KEY (id_curso, id_asignatura),
FOREIGN KEY (id_curso) REFERENCES curso (id_curso) ON DELETE RESTRICT,
FOREIGN KEY (id_asignatura) REFERENCES asignatura (id_asignatura) ON DELETE RESTRICT
);
CREATE TABLE asistente(
rut_profesor VARCHAR(9) NOT NULL CHECK (rut_profesor ~ '^[0-9k]+$'),
id_curso VARCHAR(10) NOT NULL,
PRIMARY KEY (rut_profesor, id_curso),
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT,
FOREIGN KEY (id_curso) REFERENCES curso (id_curso) ON DELETE RESTRICT
);

View File

@ -0,0 +1,71 @@
INSERT INTO region (id_region, nombre_region) VALUES (1, 'Florida');
INSERT INTO region (id_region, nombre_region) VALUES (2, 'Alabama');
INSERT INTO region (id_region, nombre_region) VALUES (3, 'Virginia');
INSERT INTO ciudad (id_ciudad, nombre_ciudad, id_region) VALUES (1, 'Pensacola', 1);
INSERT INTO ciudad (id_ciudad, nombre_ciudad, id_region) VALUES (2, 'Montgomery', 2);
INSERT INTO ciudad (id_ciudad, nombre_ciudad, id_region) VALUES (3, 'Virginia Beach', 3);
INSERT INTO apoderado (rut_apoderado, nombres, apellidos, direccion, id_ciudad) VALUES ('14592927k', 'Christopher Barry', 'Cromer', '214 Edison Dr.', 1);
INSERT INTO apoderado (rut_apoderado, nombres, apellidos, direccion, id_ciudad) VALUES ('192186099', 'Elia Alejandra', 'Chacano Troncoso', 'Avenida San Sebastian 778', 2);
INSERT INTO apoderado (rut_apoderado, nombres, apellidos, direccion, id_ciudad) VALUES ('192199859', 'Jack', 'Johnson', '320 Thomas Jefferson St.', 3);
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('254049492', 'Izabella Lynn', 'Cromer Chacano', '214 Edison Dr.', 2019, '2019-10-04', '14592927k', 1);
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('245191391', 'Tomas', 'Bunt', 'Avenida San Sebastian 778', 2018, '2010-02-05', '192186099', 2);
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('18028642k', 'Tom', 'Riddle', '320 Thomas Jefferson St.', 2017, '2014-12-31', '192199859', 3);
INSERT INTO profesor (rut_profesor, nombres, apellidos, direccion, id_ciudad) VALUES ('226174788', 'Severus', 'Snape', '232 Jackson Ave.', 1);
INSERT INTO profesor (rut_profesor, nombres, apellidos, direccion, id_ciudad) VALUES ('226779329', 'Minerva', 'McGonagall', '333 Nottingham Ln.', 2);
INSERT INTO profesor (rut_profesor, nombres, apellidos, direccion, id_ciudad) VALUES ('139414853', 'Albus', 'Dumbledore', '8450 Sparrow Rd.', 3);
INSERT INTO actividad (id_actividad, nombre, cupos, lugar, rut_profesor) VALUES (1, 'Quidditch', 14, 'Quidditch field', '226174788');
INSERT INTO actividad (id_actividad, nombre, cupos, lugar, rut_profesor) VALUES (2, 'Ogre taming', 5, 'The forbidden forest', '226779329');
INSERT INTO actividad (id_actividad, nombre, cupos, lugar, rut_profesor) VALUES (3, 'Advanced transfiguration', 2, 'Headmaster''s office', '139414853');
INSERT INTO nivel (id_nivel, nombre) VALUES (1, 'First');
INSERT INTO nivel (id_nivel, nombre) VALUES (2, 'Second');
INSERT INTO nivel (id_nivel, nombre) VALUES (3, 'Third');
INSERT INTO bloque (id_bloque, descripcion) VALUES (1, '08:10 - 09:30');
INSERT INTO bloque (id_bloque, descripcion) VALUES (2, '09:40 - 11:00');
INSERT INTO bloque (id_bloque, descripcion) VALUES (3, '11:10 - 12:30');
INSERT INTO curso (id_curso, nombre, anyo, rut_profesor) VALUES ('1A-2017', '1A', 2017, '226174788');
INSERT INTO curso (id_curso, nombre, anyo, rut_profesor) VALUES ('2B-2018', '2B', 2018, '226779329');
INSERT INTO curso (id_curso, nombre, anyo, rut_profesor) VALUES ('3C-2019', '3C', 2019, '139414853');
INSERT INTO asignatura (id_asignatura, nombre, rut_profesor) VALUES (1, 'Transfiguration', '226779329');
INSERT INTO asignatura (id_asignatura, nombre, rut_profesor) VALUES (2, 'Defense against the dark arts', '226174788');
INSERT INTO asignatura (id_asignatura, nombre, rut_profesor) VALUES (3, 'Muggle studies', '139414853');
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('254049492', 1);
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('245191391', 2);
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('18028642k', 3);
INSERT INTO actividad_nivel (id_actividad, id_nivel) VALUES (1, 1);
INSERT INTO actividad_nivel (id_actividad, id_nivel) VALUES (2, 2);
INSERT INTO actividad_nivel (id_actividad, id_nivel) VALUES (3, 3);
INSERT INTO actividad_bloque (id_actividad, id_bloque) VALUES (1, 1);
INSERT INTO actividad_bloque (id_actividad, id_bloque) VALUES (2, 2);
INSERT INTO actividad_bloque (id_actividad, id_bloque) VALUES (3, 3);
INSERT INTO horario (id_asignatura, id_bloque, sala) VALUES (1, 1, '203AC');
INSERT INTO horario (id_asignatura, id_bloque, sala) VALUES (2, 2, '301AB');
INSERT INTO horario (id_asignatura, id_bloque, sala) VALUES (3, 3, '102AA');
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('254049492', 1, 7.0);
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('245191391', 2, 4.0);
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('18028642k', 3, 1.0);
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('254049492', '1A-2017');
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('245191391', '2B-2018');
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('18028642k', '3C-2019');
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('1A-2017', 1);
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('2B-2018', 2);
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('3C-2019', 3);
INSERT INTO asistente (rut_profesor, id_curso) VALUES ('139414853', '1A-2017');
INSERT INTO asistente (rut_profesor, id_curso) VALUES ('226174788', '2B-2018');
INSERT INTO asistente (rut_profesor, id_curso) VALUES ('226779329', '3C-2019');

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

153
doc/Informe/e2/Informe2.tex Normal file
View File

@ -0,0 +1,153 @@
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{array}
\usepackage{adjustbox}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm,a4paper]{geometry}
\usepackage{amsmath}
\usepackage{verbatim}
\usepackage{courier}
\usepackage{listings}
\usepackage{xcolor}
\lstdefinestyle{freefempp}{
language=SQL,
basicstyle=\footnotesize\ttfamily,
commentstyle=\itshape\color{gray},
keywordstyle=\color{blue},
numberstyle=\color{red},
stringstyle=\color{red},
identifierstyle=\color{violet},
showstringspaces=false,
%float,
%frame=single,
%numbers=left
}
\lstset{
basicstyle=\footnotesize\ttfamily,
columns=flexible,
breaklines=true,
inputencoding=utf8,
extendedchars=true,
literate={á}{{\'a}}1 {é}{{\'e}}1 {í}{{\'i}}1 {ó}{{\'o}}1 {ú}{{\'u}}1 {ñ}{{\~n}}1 {Á}{{\'A}}1 {É}{{\'E}}1 {Í}{{\'I}}1 {Ó}{{\'O}}1 {Ú}{{\'U}}1 {Ñ}{{\~N}}1,
style=freefempp
}
\usepackage{titling}
\renewcommand\maketitlehooka{\null\mbox{}\vfill}
\renewcommand\maketitlehookd{\vfill\null}
\usepackage{hyperref}
\hypersetup{colorlinks=true,allcolors=black}
\usepackage{hypcap}
\title{\textbf{Proyecto Semestral de Base de Datos\\Entrega 2}}
\author{Christopher Cromer\\\\Profesoras Mónica Caniupán y Valeria Beratto\\Ingeniería Civil Informática}
\date{\today}
\pretitle{%
\begin{center}
\LARGE
\includegraphics[width=4cm]{ubblogo.png}\\[\bigskipamount]
}
\posttitle{\end{center}}
\begin{document}
\clearpage
\hypersetup{pageanchor=false}
\begin{titlingpage}
\maketitle
\end{titlingpage}
\thispagestyle{empty}
\newpage
\clearpage
\thispagestyle{empty}
\tableofcontents
\newpage
\hypersetup{pageanchor=true}
\pagenumbering{arabic}
\section{Introducción}
El objetivo de este trabajo es modelar un sistema para los colegios municipales de la región del Bío-Bío con el propósito de almacenar y consultar en una base de datos de PostgreSQL con información el colegio.
\newpage
\section{Consultas}
\subsection{Consulta \texorpdfstring{$Q_1$}{$Q_1$}}
\lstinputlisting{q1.sql}
\subsubsection{Resultado de \texorpdfstring{$Q_1$}{$Q_1$}}
\begin{center}
\includegraphics[width=0.90\textwidth,height=0.90\textheight,keepaspectratio]{q1.png}
\end{center}
\subsection{Consulta \texorpdfstring{$Q_2$}{$Q_2$}}
\lstinputlisting{q2.sql}
\subsubsection{Resultado de \texorpdfstring{$Q_2$}{$Q_2$}}
\begin{center}
\includegraphics[keepaspectratio]{q2.png}
\end{center}
\newpage
\subsection{Consulta \texorpdfstring{$Q_3$}{$Q_3$}}
\lstinputlisting{q3.sql}
\subsubsection{Resultado de \texorpdfstring{$Q_3$}{$Q_3$}}
\begin{center}
\includegraphics[keepaspectratio]{q3.png}
\end{center}
\subsection{Consulta \texorpdfstring{$Q_4$}{$Q_4$}}
\lstinputlisting{q4.sql}
\subsubsection{Resultado de \texorpdfstring{$Q_4$}{$Q_4$}}
\begin{center}
\includegraphics[keepaspectratio]{q4.png}
\end{center}
\newpage
\subsection{Consulta \texorpdfstring{$Q_5$}{$Q_5$}}
\lstinputlisting{q5.sql}
\subsubsection{Resultado de \texorpdfstring{$Q_5$}{$Q_5$}}
\begin{center}
\includegraphics[keepaspectratio]{q5.png}
\end{center}
\subsection{Consulta \texorpdfstring{$Q_6$}{$Q_6$}}
\lstinputlisting{q6.sql}
\subsubsection{Resultado de \texorpdfstring{$Q_6$}{$Q_6$}}
\begin{center}
\includegraphics[keepaspectratio]{q6.png}
\end{center}
\newpage
\section{Script SQL}
\subsection{Crear tablas}
\lstinputlisting{crear_tablas.sql}
\newpage
\subsection{Insertar duplas}
\lstinputlisting{insertar_duplas.sql}
\end{document}

View File

@ -0,0 +1,152 @@
CREATE TABLE region(
id_region SMALLSERIAL UNIQUE,
nombre_region VARCHAR(20) NOT NULL,
PRIMARY KEY (id_region)
);
CREATE TABLE ciudad(
id_ciudad SMALLSERIAL UNIQUE,
nombre_ciudad VARCHAR(20) NOT NULL,
id_region SMALLINT,
PRIMARY KEY (id_ciudad),
FOREIGN KEY (id_region) REFERENCES region (id_region) ON DELETE RESTRICT
);
CREATE TABLE apoderado(
rut_apoderado VARCHAR(9) NOT NULL UNIQUE CHECK (rut_apoderado ~ '^[0-9k]+$'),
nombres VARCHAR(50) NOT NULL,
apellidos VARCHAR(50) NOT NULL,
direccion VARCHAR(30) NOT NULL,
id_ciudad SMALLINT,
PRIMARY KEY (rut_apoderado),
FOREIGN KEY (id_ciudad) REFERENCES ciudad (id_ciudad) ON DELETE RESTRICT
);
CREATE TABLE alumno(
rut_alumno VARCHAR(9) NOT NULL UNIQUE CHECK (rut_alumno ~ '^[0-9k]+$'),
nombres VARCHAR(50) NOT NULL,
apellidos VARCHAR(50) NOT NULL,
direccion VARCHAR(30) NOT NULL,
id_ciudad SMALLINT,
anyo_ingreso SMALLINT CHECK (anyo_ingreso > 1980),
fecha_nacimiento DATE NOT NULL CHECK (fecha_nacimiento > '1980-01-01'),
rut_apoderado VARCHAR(9) NOT NULL CHECK (rut_apoderado ~ '^[0-9k]+$'),
PRIMARY KEY (rut_alumno),
FOREIGN KEY (id_ciudad) REFERENCES ciudad (id_ciudad) ON DELETE RESTRICT,
FOREIGN KEY (rut_apoderado) REFERENCES apoderado (rut_apoderado) ON DELETE RESTRICT
);
CREATE TABLE profesor(
rut_profesor VARCHAR(9) NOT NULL UNIQUE CHECK (rut_profesor ~ '^[0-9k]+$'),
nombres VARCHAR(50) NOT NULL,
apellidos VARCHAR(50) NOT NULL,
direccion VARCHAR(30) NOT NULL,
id_ciudad SMALLINT,
PRIMARY KEY (rut_profesor),
FOREIGN KEY (id_ciudad) REFERENCES ciudad (id_ciudad) ON DELETE RESTRICT
);
CREATE TABLE actividad(
id_actividad SERIAL UNIQUE,
nombre VARCHAR(50) NOT NULL,
cupos SMALLINT CHECK (cupos > 0),
lugar VARCHAR(20) NOT NULL,
rut_profesor VARCHAR(9) NOT NULL CHECK (rut_profesor ~ '^[0-9k]+$'),
PRIMARY KEY (id_actividad),
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT
);
CREATE TABLE nivel(
id_nivel SERIAL UNIQUE,
nombre VARCHAR(20) NOT NULL,
PRIMARY KEY (id_nivel)
);
CREATE TABLE bloque(
id_bloque SERIAL UNIQUE,
descripcion VARCHAR(20) NOT NULL,
PRIMARY KEY (id_bloque)
);
CREATE TABLE curso(
id_curso VARCHAR(10) NOT NULL UNIQUE,
nombre VARCHAR(6) NOT NULL,
anyo SMALLINT CHECK (anyo > 1980),
rut_profesor VARCHAR(9) NOT NULL CHECK (rut_profesor ~ '^[0-9k]+$'),
PRIMARY KEY (id_curso),
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT
);
CREATE TABLE asignatura(
id_asignatura SERIAL UNIQUE,
nombre VARCHAR(50) NOT NULL,
rut_profesor VARCHAR(9) NOT NULL CHECK (rut_profesor ~ '^[0-9k]+$'),
PRIMARY KEY (id_asignatura),
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT
);
CREATE TABLE participar(
rut_alumno VARCHAR(9) NOT NULL CHECK (rut_alumno ~ '^[0-9k]+$'),
id_actividad INT,
PRIMARY KEY (rut_alumno, id_actividad),
FOREIGN KEY (rut_alumno) REFERENCES alumno (rut_alumno) ON DELETE RESTRICT,
FOREIGN KEY (id_actividad) REFERENCES actividad (id_actividad) ON DELETE RESTRICT
);
CREATE TABLE actividad_nivel(
id_actividad INT,
id_nivel INT,
PRIMARY KEY (id_actividad, id_nivel),
FOREIGN KEY (id_actividad) REFERENCES actividad (id_actividad) ON DELETE RESTRICT,
FOREIGN KEY (id_nivel) REFERENCES nivel (id_nivel) ON DELETE RESTRICT
);
CREATE TABLE actividad_bloque(
id_actividad INT,
id_bloque INT,
PRIMARY KEY (id_actividad, id_bloque),
FOREIGN KEY (id_actividad) REFERENCES actividad (id_actividad) ON DELETE RESTRICT,
FOREIGN KEY (id_bloque) REFERENCES bloque (id_bloque) ON DELETE RESTRICT
);
CREATE TABLE horario(
id_asignatura INT,
id_bloque INT,
sala VARCHAR(20) NOT NULL,
PRIMARY KEY (id_asignatura, id_bloque),
FOREIGN KEY (id_asignatura) REFERENCES asignatura (id_asignatura) ON DELETE RESTRICT,
FOREIGN KEY (id_bloque) REFERENCES bloque (id_bloque) ON DELETE RESTRICT
);
CREATE TABLE registro(
rut_alumno VARCHAR(9) NOT NULL CHECK (rut_alumno ~ '^[0-9k]+$'),
id_asignatura INT,
nota NUMERIC(2,1) CHECK (nota >= 1.0 AND nota <= 7.0),
PRIMARY KEY (rut_alumno, id_asignatura),
FOREIGN KEY (rut_alumno) REFERENCES alumno (rut_alumno) ON DELETE RESTRICT,
FOREIGN KEY (id_asignatura) REFERENCES asignatura (id_asignatura) ON DELETE RESTRICT
);
CREATE TABLE cursar(
rut_alumno VARCHAR(9) NOT NULL CHECK (rut_alumno ~ '^[0-9k]+$'),
id_curso VARCHAR(10) NOT NULL,
PRIMARY KEY (rut_alumno, id_curso),
FOREIGN KEY (rut_alumno) REFERENCES alumno (rut_alumno) ON DELETE RESTRICT,
FOREIGN KEY (id_curso) REFERENCES curso (id_curso) ON DELETE RESTRICT
);
CREATE TABLE asociado(
id_curso VARCHAR(10) NOT NULL,
id_asignatura INT,
PRIMARY KEY (id_curso, id_asignatura),
FOREIGN KEY (id_curso) REFERENCES curso (id_curso) ON DELETE RESTRICT,
FOREIGN KEY (id_asignatura) REFERENCES asignatura (id_asignatura) ON DELETE RESTRICT
);
CREATE TABLE asistente(
rut_profesor VARCHAR(9) NOT NULL CHECK (rut_profesor ~ '^[0-9k]+$'),
id_curso VARCHAR(10) NOT NULL,
PRIMARY KEY (rut_profesor, id_curso),
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT,
FOREIGN KEY (id_curso) REFERENCES curso (id_curso) ON DELETE RESTRICT
);

View File

@ -0,0 +1,101 @@
INSERT INTO region (id_region, nombre_region) VALUES (1, 'Bío Bío');
INSERT INTO region (id_region, nombre_region) VALUES (2, 'Ñuble');
INSERT INTO region (id_region, nombre_region) VALUES (3, 'Virginia');
INSERT INTO ciudad (id_ciudad, nombre_ciudad, id_region) VALUES (1, 'Pensacola', 1);
INSERT INTO ciudad (id_ciudad, nombre_ciudad, id_region) VALUES (2, 'Montgomery', 2);
INSERT INTO ciudad (id_ciudad, nombre_ciudad, id_region) VALUES (3, 'Virginia Beach', 3);
INSERT INTO apoderado (rut_apoderado, nombres, apellidos, direccion, id_ciudad) VALUES ('14592927k', 'Christopher Barry', 'Cromer', '214 Edison Dr.', 1);
INSERT INTO apoderado (rut_apoderado, nombres, apellidos, direccion, id_ciudad) VALUES ('192186099', 'Elia Alejandra', 'Chacano Troncoso', 'Avenida San Sebastian 778', 2);
INSERT INTO apoderado (rut_apoderado, nombres, apellidos, direccion, id_ciudad) VALUES ('192199859', 'Jack', 'Johnson', '320 Thomas Jefferson St.', 3);
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('254049492', 'Isabella Lynn', 'Cromer Chacano', '214 Edison Dr.', 2019, '2019-10-04', '14592927k', 1);
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('245191391', 'Tomas', 'Bunt', 'Avenida San Sebastian 778', 2018, '2010-02-05', '192186099', 2);
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('18028642k', 'Tom', 'Riddle', '320 Thomas Jefferson St.', 2017, '2014-12-31', '192199859', 3);
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('22690395k', 'Draco', 'Malfoy', '743 Thames Ave.', 2017, '2006-10-04', '192199859', 1);
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('215221350', 'Victor', 'Krum', '9282 Park Way', 2017, '2007-02-12', '192199859', 1);
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('144715179', 'Pansy', 'Parkinson', '339 Mobile Hwy.', 2017, '2008-12-03', '192199859', 1);
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('86210681', 'Oliver', 'Wood', '323 Crane Ave.', 2017, '2007-01-02', '192199859', 1);
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('20084453k', 'Theodore', 'Nott', '848 Short Way', 2017, '2006-02-04', '192199859', 1);
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('133765859', 'Cormac', 'McLaggen', '484 9th Ave.', 2017, '2007-01-08', '192199859', 1);
INSERT INTO profesor (rut_profesor, nombres, apellidos, direccion, id_ciudad) VALUES ('226174788', 'Severus', 'Snape', '232 Jackson Ave.', 1);
INSERT INTO profesor (rut_profesor, nombres, apellidos, direccion, id_ciudad) VALUES ('226779329', 'Minerva', 'McGonagall', '333 Nottingham Ln.', 2);
INSERT INTO profesor (rut_profesor, nombres, apellidos, direccion, id_ciudad) VALUES ('139414853', 'Albus', 'Dumbledore', '8450 Sparrow Rd.', 3);
INSERT INTO actividad (id_actividad, nombre, cupos, lugar, rut_profesor) VALUES (1, 'Quidditch', 14, 'Quidditch field', '226174788');
INSERT INTO actividad (id_actividad, nombre, cupos, lugar, rut_profesor) VALUES (2, 'Ogre taming', 5, 'The forbidden forest', '226779329');
INSERT INTO actividad (id_actividad, nombre, cupos, lugar, rut_profesor) VALUES (3, 'Advanced transfiguration', 2, 'Headmaster''s office', '139414853');
INSERT INTO actividad (id_actividad, nombre, cupos, lugar, rut_profesor) VALUES (4, 'Rugby', 30, 'Rugby field', '226174788');
INSERT INTO nivel (id_nivel, nombre) VALUES (1, 'Primero');
INSERT INTO nivel (id_nivel, nombre) VALUES (2, 'Segundo');
INSERT INTO nivel (id_nivel, nombre) VALUES (3, 'Tercero');
INSERT INTO bloque (id_bloque, descripcion) VALUES (1, '08:10 - 09:30');
INSERT INTO bloque (id_bloque, descripcion) VALUES (2, '09:40 - 11:00');
INSERT INTO bloque (id_bloque, descripcion) VALUES (3, '11:10 - 12:30');
INSERT INTO curso (id_curso, nombre, anyo, rut_profesor) VALUES ('1A-2019', '1A', 2019, '226174788');
INSERT INTO curso (id_curso, nombre, anyo, rut_profesor) VALUES ('2B-2019', '2B', 2019, '226779329');
INSERT INTO curso (id_curso, nombre, anyo, rut_profesor) VALUES ('3C-2019', '3C', 2019, '139414853');
INSERT INTO curso (id_curso, nombre, anyo, rut_profesor) VALUES ('6A-2018', '6A', 2018, '226174788');
INSERT INTO curso (id_curso, nombre, anyo, rut_profesor) VALUES ('1A-2018', '1A', 2018, '226779329');
INSERT INTO asignatura (id_asignatura, nombre, rut_profesor) VALUES (1, 'Transfiguration', '226779329');
INSERT INTO asignatura (id_asignatura, nombre, rut_profesor) VALUES (2, 'Defense against the dark arts', '226174788');
INSERT INTO asignatura (id_asignatura, nombre, rut_profesor) VALUES (3, 'Muggle studies', '139414853');
INSERT INTO asignatura (id_asignatura, nombre, rut_profesor) VALUES (4, 'Potions', '226174788');
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('254049492', 1);
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('245191391', 2);
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('18028642k', 3);
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('22690395k', 1);
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('215221350', 1);
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('144715179', 1);
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('86210681', 1);
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('20084453k', 1);
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('133765859', 1);
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('22690395k', 4);
INSERT INTO actividad_nivel (id_actividad, id_nivel) VALUES (1, 1);
INSERT INTO actividad_nivel (id_actividad, id_nivel) VALUES (2, 2);
INSERT INTO actividad_nivel (id_actividad, id_nivel) VALUES (3, 3);
INSERT INTO actividad_bloque (id_actividad, id_bloque) VALUES (1, 1);
INSERT INTO actividad_bloque (id_actividad, id_bloque) VALUES (2, 2);
INSERT INTO actividad_bloque (id_actividad, id_bloque) VALUES (3, 3);
INSERT INTO horario (id_asignatura, id_bloque, sala) VALUES (1, 1, '203AC');
INSERT INTO horario (id_asignatura, id_bloque, sala) VALUES (2, 2, '301AB');
INSERT INTO horario (id_asignatura, id_bloque, sala) VALUES (3, 3, '102AA');
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('254049492', 1, 7.0);
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('245191391', 2, 4.0);
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('18028642k', 3, 1.0);
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('22690395k', 4, 5.0);
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('86210681', 4, 3.0);
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('144715179', 4, 2.0);
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('254049492', '1A-2019');
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('245191391', '2B-2019');
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('18028642k', '3C-2019');
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('22690395k', '6A-2018');
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('215221350', '6A-2018');
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('144715179', '6A-2018');
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('86210681', '2B-2019');
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('20084453k', '2B-2019');
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('133765859', '3C-2019');
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('1A-2019', 1);
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('2B-2019', 2);
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('3C-2019', 3);
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('6A-2018', 1);
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('6A-2018', 2);
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('6A-2018', 3);
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('1A-2018', 4);
INSERT INTO asistente (rut_profesor, id_curso) VALUES ('139414853', '1A-2019');
INSERT INTO asistente (rut_profesor, id_curso) VALUES ('226174788', '2B-2019');
INSERT INTO asistente (rut_profesor, id_curso) VALUES ('226779329', '3C-2019');

BIN
doc/Informe/e2/q1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

19
doc/Informe/e2/q1.sql Normal file
View File

@ -0,0 +1,19 @@
SELECT CONCAT_WS(' ', AL.nombres, AL.apellidos) AS alumno,
CONCAT_WS(' ', AP.nombres, AP.apellidos) AS apoderado,
CO.nombre curso,
CONCAT_WS(' ', PJ.nombres, PJ.apellidos) AS jefe,
CONCAT_WS(' ', PA.nombres, PA.apellidos) AS asistente
FROM alumno AL
JOIN apoderado AP ON (AP.rut_apoderado = AL.rut_apoderado)
JOIN cursar CU ON (CU.rut_alumno = AL.rut_alumno)
JOIN curso CO ON (CO.id_curso = CU.id_curso)
JOIN profesor PJ ON (PJ.rut_profesor = CO.rut_profesor)
JOIN asistente ASI ON (ASI.id_curso = CO.id_curso)
JOIN profesor PA ON (PA.rut_profesor = ASI.rut_profesor)
JOIN ciudad C ON (C.id_ciudad = AL.id_ciudad)
JOIN region R ON (R.id_region = C.id_region)
WHERE (
CO.anyo = 2019 AND (
R.nombre_region = 'Bío Bío' OR R.nombre_region = 'Ñuble'
)
);

BIN
doc/Informe/e2/q2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

9
doc/Informe/e2/q2.sql Normal file
View File

@ -0,0 +1,9 @@
SELECT CONCAT_WS(' ', P.nombres, P.apellidos) AS profesor FROM profesor P
JOIN curso C ON (C.rut_profesor = P.rut_profesor)
WHERE P.rut_profesor NOT IN (
SELECT P2.rut_profesor FROM profesor P2
JOIN actividad A ON (A.rut_profesor = P2.rut_profesor)
JOIN actividad_nivel A2 ON (A2.id_actividad = A.id_actividad)
JOIN nivel N ON (N.id_nivel = A2.id_nivel)
WHERE (N.nombre = 'Primero' OR N.nombre = 'Segundo')
);

BIN
doc/Informe/e2/q3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

7
doc/Informe/e2/q3.sql Normal file
View File

@ -0,0 +1,7 @@
SELECT A.nombre, COUNT(*) FROM actividad A
JOIN participar P ON (P.id_actividad = A.id_actividad)
JOIN alumno A2 ON (A2.rut_alumno = P.rut_alumno)
WHERE (A2.fecha_nacimiento >= '2006-01-01'
AND A2.fecha_nacimiento <= '2008-12-31')
GROUP BY (A.nombre)
HAVING COUNT(*) > 5;

BIN
doc/Informe/e2/q4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

13
doc/Informe/e2/q4.sql Normal file
View File

@ -0,0 +1,13 @@
CREATE VIEW matriculados(curso, cantidad) AS (
SELECT C1.nombre, COUNT(*) FROM curso C1
JOIN cursar C2 ON (C2.id_curso = C1.id_curso)
WHERE (C1.anyo = 2019)
GROUP BY (C1.nombre)
);
SELECT M.curso, M.cantidad FROM matriculados M
WHERE (
M.cantidad = (
SELECT MIN(M2.cantidad) FROM matriculados M2
)
);

BIN
doc/Informe/e2/q5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

14
doc/Informe/e2/q5.sql Normal file
View File

@ -0,0 +1,14 @@
SELECT A.nombre, AVG(r.nota) FROM asignatura A
JOIN registro R ON (R.id_asignatura = A.id_asignatura)
JOIN asociado A2 ON (A2.id_asignatura = A.id_asignatura)
JOIN alumno A3 ON (A3.rut_alumno = R.rut_alumno)
WHERE (
A2.id_curso = '6A-2018'
AND R.rut_alumno NOT IN (
SELECT A4.rut_alumno FROM alumno A4
JOIN participar P ON (P.rut_alumno = A4.rut_alumno)
JOIN actividad A5 ON (A5.id_actividad = P.id_actividad)
WHERE (A5.nombre = 'Rugby' AND A4.rut_alumno = A3.rut_alumno)
)
)
GROUP BY (A.nombre);

BIN
doc/Informe/e2/q6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

24
doc/Informe/e2/q6.sql Normal file
View File

@ -0,0 +1,24 @@
CREATE VIEW total_alumnos(asignatura, cantidad) AS (
SELECT A.id_asignatura, COUNT(*) FROM asignatura A
JOIN registro R ON (R.id_asignatura = A.id_asignatura)
JOIN alumno A2 ON (A2.rut_alumno = R.rut_alumno)
JOIN asociado A3 ON (A3.id_asignatura = A.id_asignatura)
WHERE (A3.id_curso = '1A-2018')
GROUP BY (A.id_asignatura)
);
CREATE VIEW total_aprobados(asignatura, cantidad) AS (
SELECT A.id_asignatura, COUNT(*) FROM asignatura A
JOIN registro R ON (R.id_asignatura = A.id_asignatura)
JOIN alumno A2 ON (A2.rut_alumno = R.rut_alumno)
JOIN asociado A3 ON (A3.id_asignatura = A.id_asignatura)
WHERE (A3.id_curso = '1A-2018' AND R.nota >= 4)
GROUP BY (A.id_asignatura)
);
SELECT A2.nombre, TRUNC(CAST(T1.cantidad AS DECIMAL(3,2)) * 100 / CAST(T2.cantidad AS DECIMAL(3,2)),2) AS porcentaje
FROM total_aprobados T1
JOIN total_alumnos T2 ON (T2.asignatura = T1.asignatura)
JOIN asociado A ON (T1.asignatura = A.id_asignatura AND T2.asignatura = A.id_asignatura)
JOIN asignatura A2 ON (A2.id_asignatura = A.id_asignatura)
WHERE ((CAST(T1.cantidad AS DECIMAL(3,2)) * 100 / CAST(T2.cantidad AS DECIMAL(3,2))) < 50);

BIN
doc/Informe/e2/ubblogo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

32
doc/meson.build Normal file
View File

@ -0,0 +1,32 @@
docs_enabled = get_option('valadocs')
valadoc = find_program('valadoc', required: docs_enabled)
vala_doc_sources = vala_sources
vala_doc_sources += config_data_file
if docs_enabled
valadocs_deps = get_option('valadocs_deps')
docs_deps = ['--pkg=gtk+-3.0']
docs_deps += ['--pkg=libpq']
docs_deps += ['--pkg=posix']
if valadocs_deps
docs_deps += ['--deps']
endif
custom_target('valadoc',
input: vala_doc_sources,
output: 'valadoc',
command: [ valadoc,
docs_deps,
'--doclet=html',
'--internal',
'--private',
'--force',
'--package-name=@0@'.format(meson.project_name()),
'--package-version=@0@'.format(meson.project_version()),
'--vapidir=@0@'.format(join_paths(meson.source_root(), 'vapi')),
'--directory=@OUTDIR@/valadoc',
vala_doc_sources,
],
build_by_default: true,
install: true,
install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name())
)
endif

26
meson.build Normal file
View File

@ -0,0 +1,26 @@
project('colegio',
['c', 'vala'],
version: '1.0.0',
license: 'BSD-3',
default_options: [
'c_std=c11',
'b_ofast=if-release',
'b_march_native=if-release',
'b_ndebug=if-release'
]
)
add_project_arguments('-DGETTEXT_PACKAGE="' + meson.project_name() + '"', language: 'c')
debugging = get_option('debugging')
if debugging
add_project_arguments('-DDEBUG', language : 'c')
add_project_arguments('-D', 'DEBUG', language : 'vala')
endif
add_project_arguments(['--vapidir',
join_paths(meson.current_source_dir(), 'vapi')],
language: 'vala')
subdir('data')
subdir('src')
subdir('doc')

12
meson_options.txt Normal file
View File

@ -0,0 +1,12 @@
option('debugging',
type: 'boolean',
value: false,
description: 'Build with debugging preprocessor')
option('valadocs',
type: 'boolean',
value: true,
description: 'Build valadocs for the application')
option('valadocs_deps',
type: 'boolean',
value: false,
description: 'Build the valadocs of the deps of the application')

45
src/colegio.vala Normal file
View File

@ -0,0 +1,45 @@
/*
* Copyright 2019 Chris Cromer
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
namespace Colegio {
using Constants;
public class Application : global::Gtk.Application {
public Application () {
application_id = "cl.cromer.ubb.colegio";
}
public override void activate () {
var window = new MainWindow (this);
window.set_default_size (640, 480);
window.maximize ();
window.icon = new Gtk.Image.from_resource ("/cl/cromer/ubb/colegio/pixdata/icon-colegio.png").get_pixbuf ();
window.show_all ();
window.initialize ();
}
public override void startup () {
base.startup ();
}
}
public static int main (string[] args) {
Intl.setlocale (LocaleCategory.ALL, ""); // Even though this isn't a multilanguage program, this is needed so that spanish works
print ("Versión: " + VERSION + "\n");
var application = new Application ();
return application.run (args);
}
}

26
src/config.vala.in Normal file
View File

@ -0,0 +1,26 @@
/*
* Copyright 2019 Chris Cromer
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
namespace Colegio {
namespace Constants {
public const string VERSION = "@VERSION@";
public const string HOST = "localhost";
public const string PORT = "5432";
public const string OPTIONS = "";
public const string TTY = "";
public const string DATABASE = "bdd";
public const string USERNAME = "bdd";
public const string PASSWORD = "bdd";
}
}

54
src/db.vala Normal file
View File

@ -0,0 +1,54 @@
/*
* Copyright 2019 Chris Cromer
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
namespace Colegio {
namespace DB {
using Postgres;
public errordomain PostgresError {
CONNECT,
ESCAPE
}
public errordomain DBError {
INVALID_VALUE,
FOREIGN_KEY_CONSTAINT
}
public class Connection : Object {
public Database db;
public Connection (string host, string port, string options, string tty, string database, string username, string password) throws PostgresError {
db = set_db_login (host, port, options, tty, database, username, password);
if (db.get_status () != Postgres.ConnectionStatus.OK) {
throw new PostgresError.CONNECT (db.get_error_message ());
}
GLib.print ("Versión de servidor de Postgresql:" + " %d\n", db.get_server_version ());
}
public string escape (string str) throws PostgresError {
string* to = malloc ((sizeof (string) * str.length * 2) + 1); // to has to be double the size of str + 1
int error_code;
db.escape_string_conn (to, str, str.length, out error_code);
if (error_code != 0) {
throw new PostgresError.ESCAPE (db.get_error_message ());
}
string result = to;
free (to);
return result;
}
}
}
}

19
src/db/q1.vala Normal file
View File

@ -0,0 +1,19 @@
namespace Colegio {
namespace DB {
public class Q1 : Object {
public string alumno { get; set; default = ""; }
public string apoderado { get; set; default = ""; }
public string curso { get; set; default = ""; }
public string jefe { get; set; default = ""; }
public string asistente { get; set; default = ""; }
public Q1 (string alumno = "", string apoderado = "", string curso = "", string jefe = "", string asistente = "") {
this.alumno = alumno;
this.apoderado = apoderado;
this.curso = curso;
this.jefe = jefe;
this.asistente = asistente;
}
}
}
}

11
src/db/q2.vala Normal file
View File

@ -0,0 +1,11 @@
namespace Colegio {
namespace DB {
public class Q2 : Object {
public string profesor { get; set; default = ""; }
public Q2 (string profesor = "") {
this.profesor = profesor;
}
}
}
}

72
src/dbwrapper.vala Normal file
View File

@ -0,0 +1,72 @@
/*
* Copyright 2019 Chris Cromer
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
namespace Colegio {
namespace DB {
namespace Wrapper {
using Postgres;
public errordomain Field {
NOTFOUND
}
public class ResultWrapper : Object {
public unowned Result result { get; set; default = null; }
public ResultWrapper (Result? result = null) {
this.result = result;
}
public string get_string_v (int tup_num, int field_num) {
return result.get_value (tup_num, field_num);
}
public int get_int_v (int tup_num, int field_num) {
return int.parse (result.get_value (tup_num, field_num));
}
public float get_float_v (int tup_num, int field_num) {
return float.parse(result.get_value (tup_num, field_num));
}
public double get_double_v (int tup_num, int field_num) {
return double.parse (result.get_value (tup_num, field_num));
}
public string get_string_n (int tup_num, string name) throws Field {
return get_string_v (tup_num, check_field_found (result.get_field_number (name), name));
}
public int get_int_n (int tup_num, string name) throws Field {
return get_int_v (tup_num, check_field_found (result.get_field_number (name), name));
}
public float get_float_n (int tup_num, string name) throws Field {
return get_float_v (tup_num, check_field_found (result.get_field_number (name), name));
}
public double get_double_n (int tup_num, string name) throws Field {
return get_double_v (tup_num, check_field_found (result.get_field_number (name), name));
}
private int check_field_found (int field_num, string name) throws Field {
if (field_num == -1) {
throw new Field.NOTFOUND ("El campo %s no estaba en los resultados de la consulta!", name);
}
return field_num;
}
}
}
}
}

137
src/main_window.vala Normal file
View File

@ -0,0 +1,137 @@
/*
* Copyright 2019 Chris Cromer
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
namespace Colegio {
using Constants;
using DB;
[GtkTemplate (ui = "/cl/cromer/ubb/colegio/main.window.ui")]
public class MainWindow : Gtk.ApplicationWindow {
private Connection conn;
private Gtk.Grid content;
[GtkChild]
private Gtk.Box mainbox;
[GtkChild]
private Gtk.MenuItem q1;
[GtkChild]
private Gtk.MenuItem q2;
[GtkChild]
private Gtk.MenuItem q3;
[GtkChild]
private Gtk.MenuItem q4;
[GtkChild]
private Gtk.MenuItem q5;
[GtkChild]
private Gtk.MenuItem quit;
[GtkCallback]
private void on_destroy(Gtk.Widget widget) {
application.quit ();
}
[GtkCallback]
private void on_activate_menu(Gtk.MenuItem menu_item) {
if (menu_item == q1) {
var query_window = new QueryWindow (application, conn, QueryWindow.Query.Q1);
query_window.set_transient_for (this); // Set this window as the parent of the new window
query_window.initialize ();
query_window.show_all ();
}
else if (menu_item == q2) {
var query_window = new QueryWindow (application, conn, QueryWindow.Query.Q2);
query_window.set_transient_for (this); // Set this window as the parent of the new window
query_window.initialize ();
query_window.show_all ();
}
else if (menu_item == q3) {
var query_window = new QueryWindow (application, conn, QueryWindow.Query.Q3);
query_window.set_transient_for (this); // Set this window as the parent of the new window
query_window.initialize ();
query_window.show_all ();
}
else if (menu_item == q4) {
var query_window = new QueryWindow (application, conn, QueryWindow.Query.Q4);
query_window.set_transient_for (this); // Set this window as the parent of the new window
query_window.initialize ();
query_window.show_all ();
}
else if (menu_item == q5) {
var query_window = new QueryWindow (application, conn, QueryWindow.Query.Q5);
query_window.set_transient_for (this); // Set this window as the parent of the new window
query_window.initialize ();
query_window.show_all ();
}
else if (menu_item == quit) {
application.quit ();
}
}
public MainWindow (Gtk.Application application) {
Object (application: application);
// Load logo
var builder = new Gtk.Builder ();
try {
builder.add_from_resource ("/cl/cromer/ubb/colegio/main.splash.ui");
builder.connect_signals (null);
content = builder.get_object ("content_grid") as Gtk.Grid;
// Add logo to main box
mainbox.pack_start (content, true, false, 0);
}
catch (Error e) {
// This error is not fatal, so let's keep going
warning (e.message);
}
}
public void initialize () {
try {
conn = new Connection (HOST, PORT, OPTIONS, TTY, DATABASE, USERNAME, PASSWORD);
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
var msg = new Gtk.MessageDialog (this,
Gtk.DialogFlags.MODAL,
Gtk.MessageType.ERROR,
Gtk.ButtonsType.CLOSE,
"Error: No se puede conectar al base de datos!");
msg.response.connect ((response_id) => {
switch (response_id) {
case Gtk.ResponseType.CLOSE:
application.quit ();
break;
case Gtk.ResponseType.DELETE_EVENT:
application.quit ();
break;
}
msg.destroy ();
});
msg.set_title ("Error");
msg.run ();
#endif
}
}
}
}

42
src/meson.build Normal file
View File

@ -0,0 +1,42 @@
glib_dep = dependency('glib-2.0')
gobject_dep = dependency('gobject-2.0')
gtk_dep = dependency('gtk+-3.0', version: '>=3.0.0')
# gmodule-export-2.0 is needed to connect the handlers
gmodule_dep = dependency('gmodule-2.0', version: '>=2.0')
pq_dep = dependency('libpq', version: '>=9.0')
config_data = configuration_data()
config_data.set('VERSION', meson.project_version())
config_data.set('GETTEXT_PACKAGE', meson.project_name())
config_data_file = configure_file(input: 'config.vala.in',
output: 'config.vala',
configuration: config_data)
vala_sources = files(
'colegio.vala',
'db.vala',
'dbwrapper.vala',
'misc.vala',
'main_window.vala',
'queries.vala',
'query_window.vala',
'db/q1.vala',
'db/q2.vala')
sources = vala_sources
sources += main_gresource
sources += query_gresource
sources += config_data_file
vala_args = ['--vapidir=' + join_paths(meson.source_root(), 'vapi')]
inc = include_directories('./')
exe = executable(meson.project_name(),
sources,
vala_args: vala_args,
include_directories : inc,
gui_app: true,
dependencies: [glib_dep, gobject_dep, gtk_dep, gmodule_dep, pq_dep],
install: true)

167
src/misc.vala Normal file
View File

@ -0,0 +1,167 @@
/*
* Copyright 2019 Chris Cromer
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
namespace Colegio {
namespace Misc {
public errordomain InvalidRut {
INVALID,
TOOLARGE,
INVALIDVERIFIER
}
public class Percentage : Object {
public static string format_float (float value) {
return (value * 100).to_string () + "%";
}
public static string format_double (double value) {
// Remove the double precision by converting to float
return ((float) (value * (double) 100)).to_string () + "%";
}
}
public class Rut : Object {
private string clean_rut;
private string pretty_rut;
private unichar verifier;
public enum Type {
RUN,
RUT
}
public Rut (string rut) throws InvalidRut {
parse (rut);
}
private void parse (string rut) throws InvalidRut {
try {
var regex = new Regex ("^[ ]*([0-9.]{0,11}[\\-]?[0-9kK])?[ ]*$");
if (!regex.match (rut)) {
throw new InvalidRut.INVALID ("El RUT %s contiene un carácter inválido!", rut);
}
}
catch (RegexError e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
try {
var regex = new Regex ("([.-])");
string new_rut = rut.up ();
new_rut = new_rut.strip ();
rut = regex.replace (new_rut, new_rut.length, 0, "");
if (int.parse (rut.substring (0, rut.length - 1)) > 100000000) {
throw new InvalidRut.TOOLARGE ("El RUT %s es demasiado largo!", rut);
}
this.verifier = rut.get_char (rut.length - 1);
this.clean_rut = rut.substring (0, rut.length - 1);
if (generate_verfifier (this.clean_rut) != this.verifier) {
throw new InvalidRut.INVALIDVERIFIER ("El verificador %C es inválido!", this.verifier);
}
pretty();
}
catch (RegexError e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
private void pretty () {
string new_rut = "";
string temp_rut = this.clean_rut.reverse ();
int rut_length = this.clean_rut.length;
for (int i = 0; i < rut_length; i++) {
new_rut = new_rut + temp_rut.get_char(i).to_string ();
if ((i + 1) % 3 == 0) {
if (i != rut_length - 1) {
new_rut = new_rut + ".";
}
}
}
new_rut = new_rut.reverse ();
this.pretty_rut = new_rut + "-" + this.verifier.to_string ();
}
private unichar generate_verfifier (string rut) {
/**
* 1. Multiply each digit of the RUT by 2, 3, ..., 7, 2, 3, ... from the end of the RUT moving forward.
* 2. Add the partial multiplications.
* 3. Calculate the remainder of the division by 11.
* 4. The verifier is 11 minus the previous result. If the result is 10, change it to K.
*/
int multiplier = 2;
int sum = 0;
int remainder;
int division;
int rut_length = rut.length;
// Steps 1 and 2
for (int i = rut_length - 1; i >= 0; i--) {
sum = sum + (int.parse (rut.substring(i, 1)) * multiplier);
multiplier++;
if (multiplier == 8) {
multiplier = 2;
}
}
// Step 3
division = sum / 11;
division = division * 11;
remainder = sum - division;
// Step 4
if (remainder != 0) {
remainder = 11 - remainder;
}
// Let's return their verifier
if (remainder == 10) {
// Their verifier is 10 so let's return K.
return 'K';
}
else {
// Add the '0' to convert from int to unichar
return (unichar) remainder + '0';
}
}
public string get_clean_rut () {
return this.clean_rut + this.verifier.to_string ();
}
public string get_rut () {
return this.pretty_rut;
}
public Type type () {
uint rut = int.parse (this.clean_rut);
if (rut > 50000000 && rut < 100000000) {
// Company
return Type.RUT;
}
else {
// Person
return Type.RUN;
}
}
}
}
}

146
src/queries.vala Normal file
View File

@ -0,0 +1,146 @@
/*
* Copyright 2018-2019 Chris Cromer
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
namespace Colegio {
namespace Constants {
/**
* The Q1 statement
*/
public const string Q1_STATEMENT = "Mostrar el nombre de los alumnos, el nombre del apoderado, el nombre del curso cursando a la fecha, nombre del profesor jefe y profesor asistente, para aquellos alumnos que provienen de la Región del Bı́obio o Ñuble.";
/**
* The Q2 statement
*/
public const string Q2_STATEMENT = "Mostrar el nombre de los profesores que son profesores jefes de algún curso y no tienen asignada alguna actividad extraprogramática para los niveles primero o segundo.";
/**
* The Q3 statement
*/
public const string Q3_STATEMENT = "Mostrar el nombre de las actividades extraprogramáticas y la cantidad de alumnos inscritos, considerando alumnos que hayan nacido entre los años 2006 y 2008. Considere solo aquellas actividades extraprogramáticas que tengan más de 5 alumnos inscritos.";
/**
* The Q4 statement
*/
public const string Q4_STATEMENT = "Mostrar los cursos del año 2019 que tengan la menor cantidad de alumnos matriculados. TIP: Genere vistas.";
/**
* The Q5 statement
*/
public const string Q5_STATEMENT = "Muestre el nombre de las asignaturas y el promedio de notas para cada asignatura de los alumnos del curso 6A-2018 cuyos alumnos no participan en la actividad extraprogramática “Rugby”.";
/**
* The Q6 statement
*/
public const string Q6_STATEMENT = "Muestre el nombre de las asignaturas del curso 1A-2018 que tienen un nivel de aprobación menor a 50 %. Una asignatura es aprobada si la nota es mayor o igual a 4,0. TIP: utilice vistas.";
/**
* The Q1 SQL
*/
public const string Q1_SQL = "SELECT CONCAT_WS(' ', AL.nombres, AL.apellidos) AS alumno,
CONCAT_WS(' ', AP.nombres, AP.apellidos) AS apoderado,
CO.nombre curso,
CONCAT_WS(' ', PJ.nombres, PJ.apellidos) AS jefe,
CONCAT_WS(' ', PA.nombres, PA.apellidos) AS asistente
FROM alumno AL
JOIN apoderado AP ON (AP.rut_apoderado = AL.rut_apoderado)
JOIN cursar CU ON (CU.rut_alumno = AL.rut_alumno)
JOIN curso CO ON (CO.id_curso = CU.id_curso)
JOIN profesor PJ ON (PJ.rut_profesor = CO.rut_profesor)
JOIN asistente ASI ON (ASI.id_curso = CO.id_curso)
JOIN profesor PA ON (PA.rut_profesor = ASI.rut_profesor)
JOIN ciudad C ON (C.id_ciudad = AL.id_ciudad)
JOIN region R ON (R.id_region = C.id_region)
WHERE (
CO.anyo = 2019 AND (
R.nombre_region = 'Bío Bío' OR R.nombre_region = 'Ñuble'
)
);";
/**
* The Q2 SQL
*/
public const string Q2_SQL = "SELECT CONCAT_WS(' ', P.nombres, P.apellidos) AS profesor FROM profesor P
JOIN curso C ON (C.rut_profesor = P.rut_profesor)
WHERE P.rut_profesor NOT IN (
SELECT P2.rut_profesor FROM profesor P2
JOIN actividad A ON (A.rut_profesor = P2.rut_profesor)
JOIN actividad_nivel A2 ON (A2.id_actividad = A.id_actividad)
JOIN nivel N ON (N.id_nivel = A2.id_nivel)
WHERE (N.nombre = 'Primero' OR N.nombre = 'Segundo')
);";
/**
* The Q3 SQL
*/
public const string Q3_SQL = "SELECT A.nombre, COUNT(*) FROM actividad A
JOIN participar P ON (P.id_actividad = A.id_actividad)
JOIN alumno A2 ON (A2.rut_alumno = P.rut_alumno)
WHERE (A2.fecha_nacimiento >= '2006-01-01'
AND A2.fecha_nacimiento <= '2008-12-31')
GROUP BY (A.nombre)
HAVING COUNT(*) > 5;";
/**
* The Q4 SQL
*/
public const string Q4_SQL = "CREATE VIEW matriculados(curso, cantidad) AS (
SELECT C1.nombre, COUNT(*) FROM curso C1
JOIN cursar C2 ON (C2.id_curso = C1.id_curso)
WHERE (C1.anyo = 2019)
GROUP BY (C1.nombre)
);
SELECT M.curso, M.cantidad FROM matriculados M
WHERE (
M.cantidad = (
SELECT MIN(M2.cantidad) FROM matriculados M2
)
);";
/**
* The Q5 SQL
*/
public const string Q5_SQL = "SELECT A.nombre, AVG(r.nota) FROM asignatura A
JOIN registro R ON (R.id_asignatura = A.id_asignatura)
JOIN asociado A2 ON (A2.id_asignatura = A.id_asignatura)
JOIN alumno A3 ON (A3.rut_alumno = R.rut_alumno)
WHERE (
A2.id_curso = '6A-2018'
AND R.rut_alumno NOT IN (
SELECT A4.rut_alumno FROM alumno A4
JOIN participar P ON (P.rut_alumno = A4.rut_alumno)
JOIN actividad A5 ON (A5.id_actividad = P.id_actividad)
WHERE (A5.nombre = 'Rugby' AND A4.rut_alumno = A3.rut_alumno)
)
)
GROUP BY (A.nombre);";
/**
* The Q6 SQL
*/
public const string Q6_SQL = "CREATE VIEW total_alumnos(asignatura, cantidad) AS (
SELECT A.id_asignatura, COUNT(*) FROM asignatura A
JOIN registro R ON (R.id_asignatura = A.id_asignatura)
JOIN alumno A2 ON (A2.rut_alumno = R.rut_alumno)
JOIN asociado A3 ON (A3.id_asignatura = A.id_asignatura)
WHERE (A3.id_curso = '1A-2018')
GROUP BY (A.id_asignatura)
);
CREATE VIEW total_aprobados(asignatura, cantidad) AS (
SELECT A.id_asignatura, COUNT(*) FROM asignatura A
JOIN registro R ON (R.id_asignatura = A.id_asignatura)
JOIN alumno A2 ON (A2.rut_alumno = R.rut_alumno)
JOIN asociado A3 ON (A3.id_asignatura = A.id_asignatura)
WHERE (A3.id_curso = '1A-2018' AND R.nota >= 4)
GROUP BY (A.id_asignatura)
);
SELECT A2.nombre, TRUNC(CAST(T1.cantidad AS DECIMAL(3,2)) * 100 / CAST(T2.cantidad AS DECIMAL(3,2)),2) AS porcentaje
FROM total_aprobados T1
JOIN total_alumnos T2 ON (T2.asignatura = T1.asignatura)
JOIN asociado A ON (T1.asignatura = A.id_asignatura AND T2.asignatura = A.id_asignatura)
JOIN asignatura A2 ON (A2.id_asignatura = A.id_asignatura)
WHERE ((CAST(T1.cantidad AS DECIMAL(3,2)) * 100 / CAST(T2.cantidad AS DECIMAL(3,2))) < 50);";
}
}

349
src/query_window.vala Normal file
View File

@ -0,0 +1,349 @@
/*
* Copyright 2019 Chris Cromer
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
namespace Colegio {
using Constants;
using Misc;
using DB;
using DB.Wrapper;
using Postgres;
[GtkTemplate (ui = "/cl/cromer/ubb/colegio/query.window.ui")]
public class QueryWindow : Gtk.ApplicationWindow {
private Connection conn;
public enum Query {
Q1,
Q2,
Q3,
Q4,
Q5,
Q6
}
private Query query;
private enum Q1Column {
ALUMNO,
APODERADO,
CURSO,
JEFE,
ASISTENTE,
N_COLUMNS
}
private enum Q2Column {
PROFESOR,
N_COLUMNS
}
private enum Q3Column {
NOMBRE,
CANTIDAD,
N_COLUMNS
}
private enum Q4Column {
CURSO,
CANTIDAD,
N_COLUMNS
}
private enum Q5Column {
NOMBRE,
PROMEDIO,
N_COLUMNS
}
private enum Q6Column {
NOMBRE,
PORCENTAJE,
N_COLUMNS
}
private Gtk.ListStore list_store;
[GtkChild]
private Gtk.ScrolledWindow scroll_window;
[GtkChild]
private Gtk.Label statement;
[GtkChild]
private Gtk.Label sql;
[GtkChild]
private Gtk.Button run_query;
[GtkChild]
private Gtk.Button close_query;
private Gtk.TreeView query_tree;
[GtkCallback]
public void on_clicked_button (Gtk.Button button) {
if (button == run_query) {
list_store.clear ();
if (query == Query.Q1) {
var res = conn.db.exec ("
SELECT CONCAT_WS(' ', AL.nombres, AL.apellidos) AS alumno,
CONCAT_WS(' ', AP.nombres, AP.apellidos) AS apoderado,
CO.nombre curso,
CONCAT_WS(' ', PJ.nombres, PJ.apellidos) AS jefe,
CONCAT_WS(' ', PA.nombres, PA.apellidos) AS asistente
FROM alumno AL
JOIN apoderado AP ON (AP.rut_apoderado = AL.rut_apoderado)
JOIN cursar CU ON (CU.rut_alumno = AL.rut_alumno)
JOIN curso CO ON (CO.id_curso = CU.id_curso)
JOIN profesor PJ ON (PJ.rut_profesor = CO.rut_profesor)
JOIN asistente ASI ON (ASI.id_curso = CO.id_curso)
JOIN profesor PA ON (PA.rut_profesor = ASI.rut_profesor)
JOIN ciudad C ON (C.id_ciudad = AL.id_ciudad)
JOIN region R ON (R.id_region = C.id_region)
WHERE (
CO.anyo = 2019 AND (
R.nombre_region = 'Bío Bío' OR R.nombre_region = 'Ñuble'
)
);
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.db.get_error_message ());
#else
warning (conn.db.get_error_message ());
#endif
}
else {
var wra = new ResultWrapper (res);
List<Q1> list = new List<Q1> ();
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var result = new Q1 (wra.get_string_n (i, "alumno"),
wra.get_string_n (i, "apoderado"),
wra.get_string_n (i, "curso"),
wra.get_string_n (i, "jefe"),
wra.get_string_n (i, "asistente")
);
list.append (result);
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
list.foreach ((entry) => {
Gtk.TreeIter iter;
list_store.append (out iter);
list_store.set (iter,
Q1Column.ALUMNO, entry.alumno,
Q1Column.APODERADO, entry.apoderado,
Q1Column.CURSO, entry.curso,
Q1Column.JEFE, entry.jefe,
Q1Column.ASISTENTE, entry.asistente);
});
}
}
else if (query == Query.Q2) {
list_store.clear ();
var res = conn.db.exec ("
SELECT CONCAT_WS(' ', P.nombres, P.apellidos) AS profesor FROM profesor P
JOIN curso C ON (C.rut_profesor = P.rut_profesor)
WHERE P.rut_profesor NOT IN (
SELECT P2.rut_profesor FROM profesor P2
JOIN actividad A ON (A.rut_profesor = P2.rut_profesor)
JOIN actividad_nivel A2 ON (A2.id_actividad = A.id_actividad)
JOIN nivel N ON (N.id_nivel = A2.id_nivel)
WHERE (N.nombre = 'Primero' OR N.nombre = 'Segundo')
);
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.db.get_error_message ());
#else
warning (conn.db.get_error_message ());
#endif
}
else {
var wra = new ResultWrapper (res);
List<Q2> list = new List<Q2> ();
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var result = new Q2 (wra.get_string_n (i, "profesor"));
list.append (result);
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
list.foreach ((entry) => {
Gtk.TreeIter iter;
list_store.append (out iter);
list_store.set (iter,
Q2Column.PROFESOR, entry.profesor);
});
}
}
else if (query == Query.Q3) {
}
else if (query == Query.Q4) {
}
else if (query == Query.Q5) {
}
else if (query == Query.Q6) {
}
else {
this.close ();
}
}
else if (button == close_query) {
this.close ();
}
}
public QueryWindow (Gtk.Application application, Connection conn, Query query) {
Object (application: application);
this.conn = conn;
this.query = query;
// Load scroll window's content
var builder = new Gtk.Builder ();
try {
builder.add_from_resource ("/cl/cromer/ubb/colegio/query.tree.ui");
builder.connect_signals (null);
if (query == Query.Q1) {
query_tree = builder.get_object ("query_tree_q1") as Gtk.TreeView;
}
else if (query == Query.Q2) {
query_tree = builder.get_object ("query_tree_q2") as Gtk.TreeView;
}
else if (query == Query.Q3) {
query_tree = builder.get_object ("query_tree_q3") as Gtk.TreeView;
}
else if (query == Query.Q4) {
query_tree = builder.get_object ("query_tree_q4") as Gtk.TreeView;
}
else if (query == Query.Q5) {
query_tree = builder.get_object ("query_tree_q5") as Gtk.TreeView;
}
else if (query == Query.Q6) {
query_tree = builder.get_object ("query_tree_q6") as Gtk.TreeView;
}
else {
this.close ();
}
query_tree.set_visible (true);
scroll_window.add (query_tree);
}
catch (Error e) {
// This error is not fatal, so let's keep going
warning (e.message);
}
this.set_visible (true); // This fixes: Gtk-CRITICAL **: 23:58:22.139: gtk_box_gadget_distribute: assertion 'size >= 0' failed in GtkScrollbar
}
public void initialize () {
if (query == Query.Q1) {
this.set_title ("(Q1) Alumnos de Bı́obio o Ñuble");
list_store = new Gtk.ListStore (Q1Column.N_COLUMNS,
typeof (string),
typeof (string),
typeof (string),
typeof (string),
typeof (string));
query_tree.set_model (list_store);
statement.set_text (Q1_STATEMENT);
sql.set_text (Q1_SQL);
}
else if (query == Query.Q2) {
this.set_title ("(Q2) Tour values");
list_store = new Gtk.ListStore (Q2Column.N_COLUMNS,
typeof (string));
query_tree.set_model (list_store);
statement.set_text (Q2_STATEMENT);
sql.set_text (Q2_SQL);
}
else if (query == Query.Q3) {
this.set_title ("(Q3) Coordinator total");
list_store = new Gtk.ListStore (Q3Column.N_COLUMNS,
typeof (string),
typeof (uint));
query_tree.set_model (list_store);
statement.set_text (Q3_STATEMENT);
sql.set_text (Q3_SQL);
}
else if (query == Query.Q4) {
this.set_title ("(Q4) Tourist total");
list_store = new Gtk.ListStore (Q4Column.N_COLUMNS,
typeof (string),
typeof (uint));
query_tree.set_model (list_store);
statement.set_text (Q4_STATEMENT);
sql.set_text (Q4_SQL);
}
else if (query == Query.Q5) {
this.set_title ("(Q5) Vehicle total");
list_store = new Gtk.ListStore (Q5Column.N_COLUMNS,
typeof (string),
typeof (uint));
query_tree.set_model (list_store);
statement.set_text (Q5_STATEMENT);
sql.set_text (Q5_SQL);
}
else if (query == Query.Q6) {
this.set_title ("(Q6) Vehicle total");
list_store = new Gtk.ListStore (Q6Column.N_COLUMNS,
typeof (string),
typeof (uint));
query_tree.set_model (list_store);
statement.set_text (Q6_STATEMENT);
sql.set_text (Q6_SQL);
}
else {
GLib.print ("Consulta inválida!\n");
}
}
}
}