-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_logic.py
More file actions
64 lines (64 loc) · 2.1 KB
/
Copy pathdb_logic.py
File metadata and controls
64 lines (64 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# # from flask import Flask, render_template, request, redirect, url_for, abort
# from sklearn.neighbors import KNeighborsClassifier
# from sklearn.preprocessing import StandardScaler
# from sqlalchemy.exc import SQLAlchemyError
#
# # from main import Cats, db
#
#
# # def display_all(db_model: Cats):
# # return db_model.query.all()
#
# def display_all(Cats):
# return Cats.query.all()
#
#
# def add(weight: float, tail_length: float, breed: int, Cats, db):
# cat = Cats(weight=weight, tail_length=tail_length, breed=breed)
#
# try:
# db.session.add(cat)
# db.session.commit()
# # return 200 # redirect(url_for("home")) or {"id": new_cat.id}
# return Cats.query.get(cat.id)
# except SQLAlchemyError:
# db.session.rollback()
# # return 500 # abort(500, "Error while adding new record") or {"error": "Error while adding new record"}, 500
# return None
#
#
# def delete(cat_id: int, db):
# try:
# db.session.delete(cat_id)
# db.session.commit()
# # return 200 # redirect(url_for("home")) or {"id": record_id}
# return cat_id
# except SQLAlchemyError:
# db.session.rollback()
# # return 500 # abort(500, "Error while deleting record") or {"error": "Error while deleting record"}
# return None
#
#
# def predict(weight: float, tail_length: float, Cats):
# k = 3
# if Cats.query.count() < k:
# return None
# # abort(500, f"Not enough records in Cats database, must be at least: {k}") or
# # {"error": f"Not enough records in Cats database, must be at least: {k}"}, 500
#
# new_features = [[weight, tail_length]]
#
# cats_db = Cats.query.all()
# X = [[cat.weight, cat.tail_length] for cat in cats_db]
# y = [cat.breed for cat in cats_db]
#
# scaler = StandardScaler()
# X_scaled = scaler.fit_transform(X)
#
# new_features_scaled = scaler.transform(new_features)
#
# neigh = KNeighborsClassifier(n_neighbors=k)
# neigh.fit(X_scaled, y)
# prediction = neigh.predict(new_features_scaled)[0] # czy rzucać to na int?
#
# return prediction