diff options
author | Petr Šmerkl <46304018+SveterCZE@users.noreply.github.com> | 2021-04-18 00:16:48 +0200 |
---|---|---|
committer | Petr Šmerkl <46304018+SveterCZE@users.noreply.github.com> | 2021-04-18 00:16:48 +0200 |
commit | 9cceba9b3466a2e5a7e712414bdf006215d7cb18 (patch) | |
tree | 759ffa8973d32fae04acd2bf5899e0459b087b46 | |
parent | 9a9914e21a4813e1ebb810be2b3b8084067c63b4 (diff) | |
download | justice-9cceba9b3466a2e5a7e712414bdf006215d7cb18.tar.gz |
add search by persons
-rw-r--r-- | db_creation.py | 18 | ||||
-rw-r--r-- | main.py | 19 | ||||
-rw-r--r-- | models.py | 109 | ||||
-rw-r--r-- | templates/header.html | 10 | ||||
-rw-r--r-- | templates/most_common_degree.html | 28 | ||||
-rw-r--r-- | templates/results2.html | 4 | ||||
-rw-r--r-- | templates/results_persons.html | 85 | ||||
-rw-r--r-- | templates/trivia.html | 2 |
8 files changed, 205 insertions, 70 deletions
diff --git a/db_creation.py b/db_creation.py index 1d3f22c..3a92988 100644 --- a/db_creation.py +++ b/db_creation.py @@ -728,19 +728,31 @@ def create_indices(conn): "zpusob_jednani_id" ); """ - fyzicke_osoby1 = """ CREATE INDEX "fyzicke_osoby1" ON "fyzicke_osoby" ( + fyzicke_osoby1 = """ CREATE INDEX "index fyzicke_osoby1" ON "fyzicke_osoby" ( "id" ); """ + statutarni_organy_relation_4 = """ CREATE INDEX "index statutarni organ relation 4" ON "statutarni_organ_clen_relation" ( + "osoba_id" +); """ + + dr_relation_3 = """ CREATE INDEX "index dr clen relation3" ON "dr_organ_clen_relation" ( + "osoba_id" +); """ + + akcionari3 = """ CREATE INDEX "index akcionari3" ON "jediny_akcionar" ( + "akcionar_fo_id" +); """ + list_of_indices = [companies1, companies2, companies3, companies4, companies5, adresy1, adresy2, adresy3, - akcie, akcie2, akcionari1, akcionari2, dr_clen_relation1, dr_clen_relation2, dr_relation, dr_relation2, + akcie, akcie2, akcionari1, akcionari2, akcionari3, dr_clen_relation1, dr_clen_relation2, dr_relation, dr_relation2, dr_relation_3, insolvency1, insolvency2, konkurz1, konkurz2, nazvy1, nazvy2, nazvy3, ostatni_skutecnosti, ostatni_skutecnosti2, pocty_clenu_organ1, pocty_clenu_organ2, podily1, podily2, pravni_formy, pravni_formy_relation1, pravni_formy_relation2, predmety_cinnosti_relation1, predmety_cinnosti_relation2, predmety_cinnosti_relation3, predmety_podnikani_relation1, predmety_podnikani_relation2, predmety_podnikani_relation3, predmety_cinnosti1, predmety_cinnosti2, predmety_podnikani1, predmety_podnikani2, prokuriste1, prokuriste2, prokuriste3, prokuriste4, sidlo_relation1, sidlo_relation_2, sidlo_relation_3, soudni_zapis1, soudni_zapis2, spolecnici1, spolecnici2, spolecnici3, spolecnici4, spolecnici5, statutarni_organy, statutarni_organy_relation1, statutarni_organy_relation2, - statutarni_organy_relation_3, zakladni_kapital1, zakladni_kapital2, zpusob_jednani, zpusob_jednani_relation1, zpusob_jednani_relation2, + statutarni_organy_relation_3, statutarni_organy_relation_4, zakladni_kapital1, zakladni_kapital2, zpusob_jednani, zpusob_jednani_relation1, zpusob_jednani_relation2, zpusob_jednani_relation3, pravnicke_osoby1, pravnicke_osoby2, pravnicke_osoby3, pravnicke_osoby4, fyzicke_osoby1, ucel1, ucel2, ucel_relation1, ucel_relation2, ucel_relation3] i = 0 for elem in list_of_indices: @@ -287,6 +287,12 @@ def find_most_common_activity(): most_common_activity = count_common_activity() return render_template("most_common_activity.html", most_common_activity = most_common_activity) +@app.route("/most_common_degree", methods=['GET', 'POST']) +def find_most_common_degree(): + most_common_degree_before = count_common_degrees("before") + most_common_degree_after = count_common_degrees("after") + return render_template("most_common_degree.html", most_common_degree_before = most_common_degree_before, most_common_degree_after = most_common_degree_after) + def count_number_entries(): engine = create_engine('sqlite:///justice.db', echo=True) conn = engine.connect() @@ -351,6 +357,19 @@ def count_common_purpose(): conn.close() return addresses_frequency +def count_common_degrees(method): + engine = create_engine('sqlite:///justice.db', echo=True) + conn = engine.connect() + if method == "before": + text_instruction = text("SELECT titul_pred, COUNT(`titul_pred`) AS `value_occurrence` FROM fyzicke_osoby GROUP BY `titul_pred` ORDER BY `value_occurrence` DESC LIMIT 100;") + else: + text_instruction = text("SELECT titul_za, COUNT(`titul_za`) AS `value_occurrence` FROM fyzicke_osoby GROUP BY `titul_za` ORDER BY `value_occurrence` DESC LIMIT 100;") + result = conn.execute(text_instruction).fetchall() + degree_frequency = [] + for elem in result: + degree_frequency.append((elem[0], elem[1])) + return degree_frequency[1:] + def count_oldest_companies(): engine = create_engine('sqlite:///justice.db', echo=True) conn = engine.connect() @@ -128,9 +128,9 @@ class MyContribution(types.TypeDecorator): class Predmety_Podnikani_Association(db.Model): __tablename__ = 'predmety_podnikani_relation' - id = db.Column(db.Integer) + id = db.Column(db.Integer, primary_key=True) company_id = db.Column(db.Integer, db.ForeignKey('companies.id')) - predmet_podnikani_id = db.Column(db.Integer, db.ForeignKey('predmety_podnikani.id'), primary_key=True) + predmet_podnikani_id = db.Column(db.Integer, db.ForeignKey('predmety_podnikani.id')) zapis_datum = db.Column(MyType) vymaz_datum = db.Column(MyType) predmet_podnikani = db.relationship("Predmet_Podnikani", back_populates="company_predmet_podnikani") @@ -138,9 +138,9 @@ class Predmety_Podnikani_Association(db.Model): class Predmety_Cinnosti_Association(db.Model): __tablename__ = 'predmety_cinnosti_relation' - id = db.Column(db.Integer) + id = db.Column(db.Integer, primary_key=True) company_id = db.Column(db.Integer, db.ForeignKey('companies.id')) - predmet_cinnosti_id = db.Column(db.Integer, db.ForeignKey('predmety_cinnosti.id'), primary_key=True) + predmet_cinnosti_id = db.Column(db.Integer, db.ForeignKey('predmety_cinnosti.id')) zapis_datum = db.Column(MyType) vymaz_datum = db.Column(MyType) predmet_cinnosti = db.relationship("Predmet_Cinnosti") @@ -148,9 +148,9 @@ class Predmety_Cinnosti_Association(db.Model): class Ucel_Association(db.Model): __tablename__ = 'ucel_relation' - id = db.Column(db.Integer) + id = db.Column(db.Integer, primary_key=True) company_id = db.Column(db.Integer, db.ForeignKey('companies.id')) - ucel_id = db.Column(db.Integer, db.ForeignKey('ucel.id'), primary_key=True) + ucel_id = db.Column(db.Integer, db.ForeignKey('ucel.id')) zapis_datum = db.Column(MyType) vymaz_datum = db.Column(MyType) ucel = db.relationship("Ucel") @@ -176,11 +176,21 @@ class Pravni_Forma_Association_v2(db.Model): pravni_forma_text = db.relationship("Pravni_Formy") company = db.relationship("Company") +class Dozorci_Rada_Association(db.Model): + __tablename__ = 'dozorci_rada_relation' + id = db.Column(db.Integer, primary_key=True) + company_id = db.Column(db.Integer, db.ForeignKey('companies.id')) + zapis_datum = db.Column(MyType) + vymaz_datum = db.Column(MyType) + company = db.relationship("Company") + pocet_clenu = db.relationship("Pocty_Clenu_DR") + clenove = db.relationship("Dozorci_Rada_Clen_Association") + class Statutarni_Organ_Association(db.Model): __tablename__ = 'statutarni_organ_relation' - id = db.Column(db.Integer) + id = db.Column(db.Integer, primary_key=True) company_id = db.Column(db.Integer, db.ForeignKey('companies.id')) - statutarni_organ_id = db.Column(db.Integer, db.ForeignKey('statutarni_organy.id'), primary_key=True) + statutarni_organ_id = db.Column(db.Integer, db.ForeignKey('statutarni_organy.id')) zapis_datum = db.Column(MyType) vymaz_datum = db.Column(MyType) statutarni_organ_text = db.relationship("Statutarni_Organy") @@ -189,15 +199,6 @@ class Statutarni_Organ_Association(db.Model): zpusoby_jednani = db.relationship("Zpusob_Jednani_Association") clenove = db.relationship("Statutarni_Organ_Clen_Association") -class Dozorci_Rada_Association(db.Model): - __tablename__ = 'dozorci_rada_relation' - id = db.Column(db.Integer, primary_key=True) - company_id = db.Column(db.Integer, db.ForeignKey('companies.id')) - zapis_datum = db.Column(MyType) - vymaz_datum = db.Column(MyType) - pocet_clenu = db.relationship("Pocty_Clenu_DR") - clenove = db.relationship("Dozorci_Rada_Clen_Association") - class Statutarni_Organ_Clen_Association(db.Model): __tablename__ = 'statutarni_organ_clen_relation' id = db.Column(db.Integer, primary_key=True) @@ -213,10 +214,42 @@ class Statutarni_Organ_Clen_Association(db.Model): clenstvi_do = db.Column(MyType) funkce = db.Column(db.String) adresa = db.relationship("Adresy_v2") - jmeno = db.relationship("Fyzicka_Osoba", back_populates="statut_org_association") + jmeno = db.relationship("Fyzicka_Osoba") jmeno_po = db.relationship("Pravnicka_Osoba") statutarni_organ = db.relationship("Statutarni_Organ_Association") +class Fyzicka_Osoba(db.Model): + __tablename__ = "fyzicke_osoby" + id = db.Column(db.Integer, primary_key=True) + titul_pred = db.Column(db.String) + jmeno = db.Column(db.String) + prijmeni = db.Column(db.String) + titul_za = db.Column(db.String) + datum_naroz = db.Column(MyType) + statut_org_association = db.relationship("Statutarni_Organ_Clen_Association") + spolecnik_association = db.relationship("Spolecnici_Association") + prokurista_association = db.relationship("Prokurista_Association") + sole_shareholder_association = db.relationship("Jediny_Akcionar_Association") + supervisory_board_member_association = db.relationship("Dozorci_Rada_Clen_Association") + + def get_name(self): + joined_name = "" + if self.titul_pred != "0" and self.titul_pred != None: + joined_name += self.titul_pred + " " + if self.jmeno != "0" and self.jmeno != None: + joined_name += self.jmeno + " " + if self.prijmeni != "0" and self.prijmeni != None: + joined_name += self.prijmeni + if self.titul_za != "0" and self.titul_za != None: + joined_name += ", " + self.titul_za + return joined_name + + def __repr__(self): + joined_name = self.get_name() + if self.datum_naroz != 0 and self.datum_naroz != None and self.datum_naroz != "": + joined_name += ", nar. " + self.datum_naroz + return joined_name + class Dozorci_Rada_Clen_Association(db.Model): __tablename__ = 'dr_organ_clen_relation' id = db.Column(db.Integer, primary_key=True) @@ -232,6 +265,7 @@ class Dozorci_Rada_Clen_Association(db.Model): funkce = db.Column(db.String) adresa = db.relationship("Adresy_v2") jmeno = db.relationship("Fyzicka_Osoba") + dozorci_rada = db.relationship("Dozorci_Rada_Association") class Spolecnici_Association(db.Model): __tablename__ = "spolecnici" @@ -260,6 +294,7 @@ class Prokurista_Association(db.Model): adresa = db.relationship("Adresy_v2") jmeno = db.relationship("Fyzicka_Osoba") text_prokurista = db.Column(db.String) + company = db.relationship("Company") class Prokura_Common_Text_Association(db.Model): __tablename__ = "prokura_common_texts" @@ -282,6 +317,7 @@ class Jediny_Akcionar_Association(db.Model): adresa = db.relationship("Adresy_v2") jmeno = db.relationship("Fyzicka_Osoba") oznaceni_po = db.relationship("Pravnicka_Osoba") + company = db.relationship("Company") class Podily_Association(db.Model): __tablename__ = "podily" @@ -368,12 +404,12 @@ class Adresy_v2(db.Model): joined_address = "" if self.komplet_adresa != "0": return self.komplet_adresa - if self.ulice != "0": + if self.ulice != "0" and self.ulice != None: joined_address += self.ulice + " " if self.cisloText != "0" and self.cisloText != None: joined_address += self.cisloText + ", " if self.cisloPo != 0: - if self.ulice == "0": + if self.ulice == "0" and self.ulice != None: joined_address += "č.p. " joined_address += str(self.cisloPo) if self.cisloOr != 0: @@ -384,11 +420,11 @@ class Adresy_v2(db.Model): joined_address += str(self.cisloOr) + ", " if self.cisloEv != 0: joined_address += str(self.cisloEv) + ", " - if (self.castObce != "0") and (self.castObce != self.obec): + if (self.castObce != "0") and (self.castObce != self.obec) and self.castObce != None: joined_address += self.castObce + ", " if self.psc != "0" and self.psc != None: joined_address += self.psc + " " - if self.obec != "0": + if self.obec != "0" and self.obec != None: joined_address += self.obec if (self.stat != "Česká republika") and (self.stat != "Česká republika - neztotožněno"): joined_address += ", " + self.stat @@ -577,35 +613,6 @@ class Druhy_Podilu(db.Model): id = db.Column(db.Integer, primary_key=True) druh_podilu = db.Column(db.String) -class Fyzicka_Osoba(db.Model): - __tablename__ = "fyzicke_osoby" - id = db.Column(db.Integer, primary_key=True) - titul_pred = db.Column(db.String) - jmeno = db.Column(db.String) - prijmeni = db.Column(db.String) - titul_za = db.Column(db.String) - datum_naroz = db.Column(MyType) - statut_org_association = db.relationship("Statutarni_Organ_Clen_Association", back_populates="jmeno") - spolecnik_association = db.relationship("Spolecnici_Association", back_populates="jmeno") - - def get_name(self): - joined_name = "" - if self.titul_pred != "0" and self.titul_pred != None: - joined_name += self.titul_pred + " " - if self.jmeno != "0" and self.jmeno != None: - joined_name += self.jmeno + " " - if self.prijmeni != "0" and self.prijmeni != None: - joined_name += self.prijmeni - if self.titul_za != "0" and self.titul_za != None: - joined_name += ", " + self.titul_za - return joined_name - - def __repr__(self): - joined_name = self.get_name() - if self.datum_naroz != 0 and self.datum_naroz != None and self.datum_naroz != "": - joined_name += ", nar. " + self.datum_naroz - return joined_name - class Pravnicka_Osoba(db.Model): __tablename__ = "pravnicke_osoby" diff --git a/templates/header.html b/templates/header.html index 30a4ebd..14b8bda 100644 --- a/templates/header.html +++ b/templates/header.html @@ -8,4 +8,12 @@ <!-- Bootstrap CSS --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous"> <title>Search Results - Flask Justice Database</title> -<body>
\ No newline at end of file +<body> +<table class="table"> + <tr> + <td><a href="/">Veřejný rejstřík podle subjektů</a></td> + <td><a href="/osoby">Veřejný rejstřík podle fyzických osob v angažmá</a></td> + <td>Veřejný rejstřík podle právnických osob v angažmá (coming soon)</td> + <td><a href="/trivia">Zajímavosti z obchodního rejstříku</a></td> + </tr> +</table>
\ No newline at end of file diff --git a/templates/most_common_degree.html b/templates/most_common_degree.html new file mode 100644 index 0000000..72ac5b2 --- /dev/null +++ b/templates/most_common_degree.html @@ -0,0 +1,28 @@ +{% include 'header.html' %} + +<h1>Nejčastější tituly:</h1> + +<table class="table table-hover" style="width: auto"> + <thead class="thead-dark"> + <tr class="table-info"> + <th scope="col">#</th> + <th scope="col">Titul před jménem</th> + <th scope="col">Frekvence</th> + <th scope="col">Titul za jménem</th> + <th scope="col">Frekvence</th> + </tr> + </thead> + <tbody> + {% for i in range (most_common_degree_before|length) %} + <tr> + <th scope = "row">{{ i + 1 }}</th> + <td>{{ most_common_degree_before[i][0] }}</td> + <td>{{ most_common_degree_before[i][1] }}</td> + <td>{{ most_common_degree_after[i][0] }}</td> + <td>{{ most_common_degree_after[i][1] }}</td> + </tr> + {% endfor %} + </tbody> +</table> + +{% include 'footer.html' %}
\ No newline at end of file diff --git a/templates/results2.html b/templates/results2.html index 3e686da..9f41c18 100644 --- a/templates/results2.html +++ b/templates/results2.html @@ -1,7 +1,7 @@ -{% include 'header.html' %} - {% if show_form == True %} {% include 'search_form.html' %} +{% else %} + {% include 'header.html' %} {% endif %} <p><b>Počet nalezených subjektů: {{ results|length }}</b></p> diff --git a/templates/results_persons.html b/templates/results_persons.html index a3ceb38..666e8d9 100644 --- a/templates/results_persons.html +++ b/templates/results_persons.html @@ -1,24 +1,85 @@ -{% include 'header.html' %} - {% if show_form == True %} {% include 'search_form_person.html' %} +{% else %} + {% include 'header.html' %} {% endif %} <p><b>Počet nalezených osob: {{ results|length }}</b></p> +{% set count = namespace(value=0) %} + {% for row in results %} + {% set test_list = [] %} + {% for elem in row.statut_org_association %} + {% set my_dict = {} %} + {% set x = my_dict.__setitem__("adresa", elem.adresa) %} + {% set x = my_dict.__setitem__("funkce", elem.funkce) %} + {% set x = my_dict.__setitem__("nazev", elem.statutarni_organ.company.nazev) %} + {% set x = my_dict.__setitem__("ico", elem.statutarni_organ.company.ico) %} + {% set x = my_dict.__setitem__("oddil", elem.statutarni_organ.company.oddil) %} + {% set x = my_dict.__setitem__("vlozka", elem.statutarni_organ.company.vlozka) %} + {% set x = my_dict.__setitem__("soud", elem.statutarni_organ.company.soud) %} + {% set x = my_dict.__setitem__("zapis", elem.statutarni_organ.company.zapis) %} + {% set test_list = test_list.append(my_dict) %} + {% endfor %} + + {% for elem in row.supervisory_board_member_association %} + {% set my_dict = {} %} + {% set x = my_dict.__setitem__("adresa", elem.adresa) %} + {% set x = my_dict.__setitem__("funkce", elem.funkce) %} + {% set x = my_dict.__setitem__("nazev", elem.dozorci_rada.company.nazev) %} + {% set x = my_dict.__setitem__("ico", elem.dozorci_rada.company.ico) %} + {% set x = my_dict.__setitem__("oddil", elem.dozorci_rada.company.oddil) %} + {% set x = my_dict.__setitem__("vlozka", elem.dozorci_rada.company.vlozka) %} + {% set x = my_dict.__setitem__("soud", elem.dozorci_rada.company.soud) %} + {% set x = my_dict.__setitem__("zapis", elem.dozorci_rada.company.zapis) %} + {% set test_list = test_list.append(my_dict) %} + {% endfor %} -{% set count = namespace(value=0) %} -{% for row in results %} -<p>{{ row }} {{ row.statut_org_association }} {% for elem in row.spolecnik_association %} - {{ elem.company.nazev }} {{ elem.adresa }} + {% set my_dict = {} %} + {% set x = my_dict.__setitem__("adresa", elem.adresa) %} + {% set x = my_dict.__setitem__("funkce", "společník") %} + {% set x = my_dict.__setitem__("nazev", elem.company.nazev) %} + {% set x = my_dict.__setitem__("ico", elem.company.ico) %} + {% set x = my_dict.__setitem__("oddil", elem.company.oddil) %} + {% set x = my_dict.__setitem__("vlozka", elem.company.vlozka) %} + {% set x = my_dict.__setitem__("soud", elem.company.soud) %} + {% set x = my_dict.__setitem__("zapis", elem.company.zapis) %} + {% set test_list = test_list.append(my_dict) %} + {% endfor %} + + {% for elem in row.sole_shareholder_association %} + {% set my_dict = {} %} + {% set x = my_dict.__setitem__("adresa", elem.adresa) %} + {% set x = my_dict.__setitem__("funkce", "jediný akcionář") %} + {% set x = my_dict.__setitem__("nazev", elem.company.nazev) %} + {% set x = my_dict.__setitem__("ico", elem.company.ico) %} + {% set x = my_dict.__setitem__("oddil", elem.company.oddil) %} + {% set x = my_dict.__setitem__("vlozka", elem.company.vlozka) %} + {% set x = my_dict.__setitem__("soud", elem.company.soud) %} + {% set x = my_dict.__setitem__("zapis", elem.company.zapis) %} + {% set test_list = test_list.append(my_dict) %} {% endfor %} - </p> - {% for elem in row.statut_org_association %} + + {% for elem in row.prokurista_association %} + {% set my_dict = {} %} + {% set x = my_dict.__setitem__("adresa", elem.adresa) %} + {% set x = my_dict.__setitem__("funkce", "prokurista") %} + {% set x = my_dict.__setitem__("nazev", elem.company.nazev) %} + {% set x = my_dict.__setitem__("ico", elem.company.ico) %} + {% set x = my_dict.__setitem__("oddil", elem.company.oddil) %} + {% set x = my_dict.__setitem__("vlozka", elem.company.vlozka) %} + {% set x = my_dict.__setitem__("soud", elem.company.soud) %} + {% set x = my_dict.__setitem__("zapis", elem.company.zapis) %} + {% set test_list = test_list.append(my_dict) %} + {% endfor %} + + {% for elem in test_list %} {% if count.value % 2 == 0 %} {% set table_style = "table table-light" %} {% else %} {% set table_style = "table table-secondary" %} {% endif %} + <table class= "{{table_style}}" style="width: 100%"> <p></p> <tr> @@ -37,16 +98,16 @@ <tr> <td>Název subjektu:</td> - <td><b>{{ elem.statutarni_organ.company.nazev }}</b></td> + <td><b>{{ elem.nazev }}</b></td> <td>IČO:</td> - <td><a href="/{{ elem.statutarni_organ.company.ico }}"><b>{{ elem.statutarni_organ.company.ico }}</b></a></td> + <td><a href="/{{ elem.ico }}"><b>{{ elem.ico }}</b></a></td> </tr> <tr> <td>Spisová značka:</td> - <td>{{elem.statutarni_organ.company.oddil}} {{elem.statutarni_organ.company.vlozka}} vedená u {{elem.statutarni_organ.company.soud}}</td> + <td>{{elem.oddil}} {{elem.vlozka}} vedená u {{elem.soud}}</td> <td>Den zápisu:</td> - <td>{{elem.statutarni_organ.company.zapis}}</td> + <td>{{elem.zapis}}</td> </tr> </table> diff --git a/templates/trivia.html b/templates/trivia.html index 5bc274a..750706c 100644 --- a/templates/trivia.html +++ b/templates/trivia.html @@ -9,6 +9,6 @@ <p><a href="/most_common_purpose">Seznam nejčastějších účelů</a></p> <p><a href="/most_common_business">Seznam nejčastějších předmětů podnikání</a></p> <p><a href="/most_common_activity">Seznam nejčastějších předmětů činnosti</a></p> - +<p><a href="/most_common_degree">Seznam nejčastějších titulů</a></p> {% include 'footer.html' %}
\ No newline at end of file |