-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from GeorgeKontsevik/feature/refactor
fix/geocoder
- Loading branch information
Showing
7 changed files
with
437 additions
and
1,994 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
import pytest | ||
import torch | ||
import pandas as pd | ||
from sloyka import TextClassifiers | ||
# import pytest | ||
# import torch | ||
# import pandas as pd | ||
# from sloyka import TextClassifiers | ||
|
||
path_to_file = "sloyka/sample_data/raw/Адмиралтейский.csv" | ||
# path_to_file = "sloyka/sample_data/raw/Адмиралтейский.csv" | ||
|
||
@pytest.fixture | ||
def test_data(): | ||
df_predict = pd.read_csv(path_to_file, sep=";") | ||
df_predict.rename(columns={"Текст комментария": "Текст"}, inplace=True) | ||
df_predict = df_predict.dropna(subset=["Текст"]) | ||
df_predict = df_predict.head(3) | ||
return df_predict | ||
# @pytest.fixture | ||
# def test_data(): | ||
# df_predict = pd.read_csv(path_to_file, sep=";") | ||
# df_predict.rename(columns={"Текст комментария": "Текст"}, inplace=True) | ||
# df_predict = df_predict.dropna(subset=["Текст"]) | ||
# df_predict = df_predict.head(3) | ||
# return df_predict | ||
|
||
@pytest.fixture | ||
def model(): | ||
return TextClassifiers( | ||
repository_id="Sandrro/text_to_subfunction_v10", | ||
number_of_categories=1, | ||
device_type=torch.device("cpu"), | ||
) | ||
# @pytest.fixture | ||
# def model(): | ||
# return TextClassifiers( | ||
# repository_id="Sandrro/text_to_subfunction_v10", | ||
# number_of_categories=1, | ||
# device_type=torch.device("cpu"), | ||
# ) | ||
|
||
def test_cats_probs(model, test_data): | ||
expected_df = pd.DataFrame( | ||
{ | ||
"cats": [ | ||
"Вопросы граждан о проектах/планах/сроках/ходе проведения работ по благоустройству", | ||
"Не ЦУР", | ||
"Вопросы по оплате проезда в общественном транспорте", | ||
], | ||
"probs": ["1.0", "0.999", "0.98"], | ||
} | ||
) | ||
# def test_cats_probs(model, test_data): | ||
# expected_df = pd.DataFrame( | ||
# { | ||
# "cats": [ | ||
# "Вопросы граждан о проектах/планах/сроках/ходе проведения работ по благоустройству", | ||
# "Не ЦУР", | ||
# "Вопросы по оплате проезда в общественном транспорте", | ||
# ], | ||
# "probs": ["1.0", "0.999", "0.98"], | ||
# } | ||
# ) | ||
|
||
test_data[["cats", "probs"]] = pd.DataFrame( | ||
test_data["Текст"].progress_map(lambda x: model.run_text_classifier_topics(x)).to_list() | ||
) | ||
assert test_data["cats"].equals(expected_df["cats"]) | ||
assert test_data["probs"].equals(expected_df["probs"]) | ||
# test_data[["cats", "probs"]] = pd.DataFrame( | ||
# test_data["Текст"].progress_map(lambda x: model.run_text_classifier_topics(x)).to_list() | ||
# ) | ||
# assert test_data["cats"].equals(expected_df["cats"]) | ||
# assert test_data["probs"].equals(expected_df["probs"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
import pytest | ||
import geopandas as gpd | ||
from sloyka import EventDetection | ||
# import pytest | ||
# import geopandas as gpd | ||
# from sloyka import EventDetection | ||
|
||
path_to_population = "sloyka/sample_data/raw/population.geojson" | ||
path_to_data = "sloyka/sample_data/processed/messages.geojson" | ||
# path_to_population = "sloyka/sample_data/raw/population.geojson" | ||
# path_to_data = "sloyka/sample_data/processed/messages.geojson" | ||
|
||
|
||
@pytest.fixture | ||
def gdf(): | ||
gdf = gpd.read_file(path_to_data) | ||
gdf = gdf.head(6) | ||
return gdf | ||
# @pytest.fixture | ||
# def gdf(): | ||
# gdf = gpd.read_file(path_to_data) | ||
# gdf = gdf.head(6) | ||
# return gdf | ||
|
||
|
||
def test_event_detection(gdf): | ||
expected_name = "0_фурштатская_штукатурного слоя_слоя_отслоение" | ||
expected_risk = 0.405 | ||
expected_messages = [4, 5, 3, 2] | ||
event_model = EventDetection() | ||
_, events, _ = event_model.run( | ||
gdf, path_to_population, "Санкт-Петербург", 32636, min_event_size=3 | ||
) | ||
event_name = events.iloc[0]["name"] | ||
event_risk = events.iloc[0]["risk"].round(3) | ||
event_messages = [ | ||
int(mid) for mid in events.iloc[0]["message_ids"].split(", ") | ||
] | ||
assert event_name == expected_name | ||
assert event_risk == expected_risk | ||
assert all(mid in event_messages for mid in expected_messages) | ||
# def test_event_detection(gdf): | ||
# expected_name = "0_фурштатская_штукатурного слоя_слоя_отслоение" | ||
# expected_risk = 0.405 | ||
# expected_messages = [4, 5, 3, 2] | ||
# event_model = EventDetection() | ||
# _, events, _ = event_model.run( | ||
# gdf, path_to_population, "Санкт-Петербург", 32636, min_event_size=3 | ||
# ) | ||
# event_name = events.iloc[0]["name"] | ||
# event_risk = events.iloc[0]["risk"].round(3) | ||
# event_messages = [ | ||
# int(mid) for mid in events.iloc[0]["message_ids"].split(", ") | ||
# ] | ||
# assert event_name == expected_name | ||
# assert event_risk == expected_risk | ||
# assert all(mid in event_messages for mid in expected_messages) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters