Skip to content

Conversation

@thaelathy
Copy link
Contributor

A django web application to mark hotels match.

README.md Outdated

## Main page

```/index``` is the main page. It shows you a map (google or leaflet) with
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the map?

from django.contrib import admin
from django.http import HttpResponse

from .models import Iteration, MarkedObjects
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

я за полные импорты

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

у меня пайчарм против тогда будет. если я установлю прям приложение, то из-за того, что оно лежит в подпапке, оно будет импортить из установленного приложения, а не откуда надо. ну и из-за того, что у меня нет этого установленного приложения, пайчарм не ходит по декларациям.

это всё можно пофиксить при помощи sys.path.append и настройками ИДЕ, но запускающему чуваку, которому просто надо чтобы запустилось один раз, надо будет это тоже проделывать, что приведет к вопросам ко мне (фиксится ридми, но периодическое нечтение ридми ничем не фиксится).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Имхо, редактор - это не причина.



class MarkedObjects(models.Model):
obj_id = models.IntegerField()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

мне кажется, что лучше тут и дальше полностью object_X

meta = models.TextField()


class MarkedObjects(models.Model):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

что такое obj, а что такое other? реквестирую докстринг

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

возможно здесь вообще лучше сделать просто таблицу объектов и сделать внешнюю m2m?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obj - это obj, а other - это other_obj без четырех букв) напишу
м2м не хочу потому что будет малоюзабельно: тут дело в том, что предполагается матчинг сферических объектов в вакууме и мне надо получить на выходе только таблицу, что с чем матчится и некоторую метаинфу, по которой можно было бы обучать.

если бы это какой-то веб был (в смысле в продакшене и где больше одного юзера), где надо хранить инфу об объектах и выводить всякое разное - имело бы смысл.

а так мне придется сначала распихать это всё по разным таблицам, а потом собирать обратно. если очень надо будет - шелл скриптом это можно сделать из оригинальных данных, а не записанных мной.

<head>


<style> html, body, #map { height: 100%; width: 100%; padding: 0; margin: 0; } </style>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

отступы бы добавить (2 пробела)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

while True:
lineno = random.randint(1, len(settings.dataset))
row = settings.dataset[lineno: lineno + 1].to_dict(orient='records')[0]
if float(row['dist_1']) > 0.02: # ~3km
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в константу наверх?

break
row['obj_lat'], row['obj_lon'] = map(
float,
row.pop('geometry').replace('POINT (', '').replace(')', '').split()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

предлагаю это преобразование в какой-нибудь отдельный метод запихнуть


import os
import pandas as pd

Copy link

@jbenua jbenua Mar 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+ строка после импортов

STATIC_URL = '/static/'


dataset = pd.read_csv('../hotels_geomatched.csv', sep='\t',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

из конфига?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вообще на мой взгляд идея строить датасет в настроечках - не очень. хочу я shell, например вызвать, а оно мне жахнет все это

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Категорически против операций в сеттингах жЫрнее чем O(1).

@@ -0,0 +1,7 @@
osmium
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

версии?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

предположила, что это будет только на локальных тачках, так что может сойти что угодно имеющееся

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ну хз, breaking changes и все такое. я бы прибила гвоздями

</body>

<script>
var map = new L.Map('map', {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

я не знаток js, тут не нужен свой скоуп?

(function() {
 // code
})();

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не, не обязательно, эти глобально просто определятся, тут все же не совсем продакшон-код. но по-хорошему, надо, конечно, завернуть в метод и повесить на коллбэк загрузки страницы

</body>

<script>
var map = new L.Map('map', {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не, не обязательно, эти глобально просто определятся, тут все же не совсем продакшон-код. но по-хорошему, надо, конечно, завернуть в метод и повесить на коллбэк загрузки страницы



function setNewData () {
var fss = $.getJSON('http://127.0.0.1:8000/row/', function(features) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

из конфига порт?


from shapely.geometry import Point

from .internals.constants import (
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

я за полные пути

import geopandas as gpd
import pandas as pd


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это сторонний же модуль? почему отступы тогда?



class HotelsOSMHandler(OSMHandler):
def not_dependency(self, elem):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_not_dependency

Comment on lines +32 to +58
osmhandler = HotelsOSMHandler()
# scan the input file and fills the handler list accordingly
osmhandler.apply_file("../hotels_wo_unwanted.osm")

# transform the list into a pandas DataFrame
data_colnames = ['type', 'id', 'ntags', 'name', 'geometry', ]

crs = {'init': 'epsg:4326'} # OSM
gdf_osm = gpd.GeoDataFrame(osmhandler.osm_data, crs=crs, columns=data_colnames)


df = pd.read_csv('../hotels_booking_latest.csv', sep='\t', header=None,
names=[
'other_id', 'other_lat', 'other_lon',
'other_name', 'addr', 'n',
'm', 'i', 'rating',
'web', 'j', 'trans'],
na_values='None')
geometry = [Point(xy) for xy in zip(df.other_lat, df.other_lon)]


crs2 = {'init': 'epsg:3857'} # google
gdf_booking = gpd.GeoDataFrame(df, crs=crs2, geometry=geometry)

c = ckdnearest(gdf_osm, gdf_booking, gdfB_cols=B_COLS)
c.sort_values(by=['type', 'id'])
c.to_csv('hotels_geomatched.csv', sep='\t', index_label='lineno')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в __main__?

gdf_osm = gpd.GeoDataFrame(osmhandler.osm_data, crs=crs, columns=data_colnames)


df = pd.read_csv('../hotels_booking_latest.csv', sep='\t', header=None,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

путь в константу

from sklearn.tree import DecisionTreeClassifier
from sklearn.dummy import DummyClassifier
from ..internals.tools import get_df, get_sets, get_fit_classifier

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 стр

from sklearn.metrics import accuracy_score
from sklearn.tree import DecisionTreeClassifier
from sklearn.dummy import DummyClassifier
from ..internals.tools import get_df, get_sets, get_fit_classifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

я за полные пути

Comment on lines +7 to +33
marked_df = get_df(os.environ['MARKED_DATA'])

# Here we get 50/50 true and false marked objects
X_train, X_test, y_train, y_test = get_sets(marked_df, test_size=0.5, get_all_as_test=False)


clf = get_fit_classifier(DummyClassifier, X_train, y_train)
y_pred = clf.predict(X_test)
dummy_score = accuracy_score(y_test, y_pred)


clf = get_fit_classifier(DecisionTreeClassifier, X_train, y_train)
y_pred = clf.predict(X_test)
clf_score = accuracy_score(y_test, y_pred)

print("50/50 dataset")
print(f"Dummy accuracy: {dummy_score}, should be ~0.5")
print(f"DecisionTreeClassifier accuracy: {clf_score}, should be more than Dummy accuracy")


_, X_test, _, y_test = get_sets(marked_df, test_size=0.5, get_all_as_test=True)

y_pred = clf.predict(X_test)
clf_score = accuracy_score(y_test, y_pred)

print("Full dataset")
print(f"DecisionTreeClassifier accuracy: {clf_score}, should be more than Dummy accuracy")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

предлагаю завернуть в main

import os

from setuptools import setup

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 стр

@@ -0,0 +1,43 @@
import os

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не нужна строка

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants