Skip to content

Commit

Permalink
fixed calculation upload shpefiles
Browse files Browse the repository at this point in the history
  • Loading branch information
gtsarik committed Dec 9, 2017
1 parent 8a19c36 commit e78eead
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 109 deletions.
39 changes: 21 additions & 18 deletions src/core/editor_shapefiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def getUploadListTifFiles(customer, dataset, *args):
# attributes_reports = AttributesReport.objects.filter(
# user=customer, data_set=dataset)

# print '!!!!!!!!!!!!!!!!!!! attributes_tmp ====================== ', attributes_tmp
# print '!!!!!!!!!!!!!!!!!!! IS TS ====================== ', dataset.is_ts

# print '!!!!!!!!!!!!!!!!!!! statistic ====================== ', statistic
# print '!!!!!!!!!!!!!!!!!!! Attributes ====================== ', attributes
Expand Down Expand Up @@ -336,24 +336,26 @@ def getUploadListTifFiles(customer, dataset, *args):
# attributes_reports = sorted(attributes_reports.keys())

# print '!!!!!!!!!!!!!!!!!!! 2 attributes_reports ====================== ', attributes_reports
try:
for attr in attributes:
attr_list = attr.split('_')
select_shd = ShelfData.objects.get(id=attr_list[1])
name_1 = select_shd.root_filename
name_2 = dataset.results_directory.split('/')[0]
tif_path = os.path.join(PROJECTS_PATH, dataset.results_directory, name_1)

for attr in attributes:
attr_list = attr.split('_')
select_shd = ShelfData.objects.get(id=attr_list[1])
name_1 = select_shd.root_filename
name_2 = dataset.results_directory.split('/')[0]
tif_path = os.path.join(PROJECTS_PATH, dataset.results_directory, name_1)

# print '!!!!!!!!!!!!!!!!!!! TIF PATH ====================== ', tif_path
# print '!!!!!!!!!!!!!!!!!!! TIF PATH ====================== ', tif_path

fl_tif = '{0}/{1}_{2}.{3}.tif'.format(tif_path, SUB_DIRECTORIES_REVERCE[statistic], name_1, name_2)
new_fl_tif = '{0}$$${1}$$${2}$$$'.format(attr_list[1], select_shd.attribute_name, fl_tif)
# str_data_db = '{0}$$${1}$$$'.format(attr_list[1], fl_tif)
fl_tif = '{0}/{1}_{2}.{3}.tif'.format(tif_path, SUB_DIRECTORIES_REVERCE[statistic], name_1, name_2)
new_fl_tif = '{0}$$${1}$$${2}$$$'.format(attr_list[1], select_shd.attribute_name, fl_tif)
# str_data_db = '{0}$$${1}$$$'.format(attr_list[1], fl_tif)

# print '!!!!!!!!!!!!!!!!!!! TIF PATH NAME ====================== ', fl_tif
# print '!!!!!!!!!!!!!!!!!!! TIF PATH NAME ====================== ', fl_tif

list_files_tif.append(new_fl_tif)
# list_data_db.append(str_data_db)
list_files_tif.append(new_fl_tif)
# list_data_db.append(str_data_db)
except Exception, e:
print '!!!!!!!!!! ERROR ATTR ========================= ', e

# print '!!!!!!!!!! FILE ========================= ', list_files_tif
# print '!!!!!!!!!! DATA DB ========================= ', list_data_db
Expand Down Expand Up @@ -388,7 +390,8 @@ def create_new_calculations_aoi(customer, doc_kml, data_set, *args):
outer_coord, inner_coord = get_coord_aoi(doc_kml)
list_file_tif = getUploadListTifFiles(customer, data_set, *args)

# print '!!!!!!!!!!!!!!! CREATE Outer Coord ===================== ', outer_coord
print '!!!!!!!!!!!!!!! CREATE Outer Coord ===================== ', outer_coord
print '!!!!!!!!!!!!!!! LIST TIF FILES ===================== ', list_file_tif

# all_coord = outer_coord + inner_coord
kml_name ='{0} {1} AREA COORDINATE'.format(customer, data_set)
Expand Down Expand Up @@ -574,15 +577,15 @@ def create_new_calculations_aoi(customer, doc_kml, data_set, *args):
total = '{0:,}'.format(float(nl[3])).replace(',', ',')

if list_val:
print '!!!!!!!!!!!!!!!!! LIST VAL ======================== ', list_val
# print '!!!!!!!!!!!!!!!!! LIST VAL ======================== ', list_val

total_area_tmp = float(list_val[0])
units_per_ha = list_val[1]
total = list_val[2]
len_list_val = len(list_val)

for n in xrange(3, len_list_val, 3):
print '!!!!!!!!!!!!!!! list_val[n] =========================== ', list_val[n]
# print '!!!!!!!!!!!!!!! list_val[n] =========================== ', list_val[n]

# if (n+3) < len_list_val:
total_area_tmp -= float(list_val[n])
Expand Down
50 changes: 50 additions & 0 deletions src/core/functions_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,53 @@ def getTsResultDirectory(dataset):
# print '!!!!!!!!!!!!!!!!!!!! TS ========================= ', is_ts

return dirs_list


def getCountTs(dataset, shd):
# print '!!!!!!!!!!!!!!!!! SHD ===================== ', shd

is_ts = dataset.is_ts
count_ts = 0

path_cur_proj = dataset.results_directory
path_to_proj = os.path.join(PROJECTS_PATH, path_cur_proj)

# print '!!!!!!!!!!!!!!!!! path_to_proj ===================== ', path_to_proj

try:
if os.path.exists(path_to_proj):
pr_root, pr_dirs, pr_files = os.walk(path_to_proj).next()
pr_dirs.sort()

# print '!!!!!!!!!!!!!!!!! pr_dirs ===================== ', pr_dirs


for d in pr_dirs:
# print '!!!!!!!!!!!!!!!!! d ===================== ', d
# print '!!!!!!!!!!!!!!!!! IN SHD ===================== ', shd
# print '!!!!!!!!!!!!!!!!! d in shd ===================== ', d in shd
if d in shd:
path_to_subdir = os.path.join(path_to_proj, d)
sub_root, sub_dirs, sub_files = os.walk(path_to_subdir).next()
sub_dirs.sort()

# print '!!!!!!!!!!!!!!!!! path_to_subdir ===================== ', path_to_subdir

for sd in sub_dirs:
attr_dir = os.path.join(path_to_subdir, sd)
attr_root, attr_dirs, attr_files = os.walk(attr_dir).next()
attr_files.sort()

# print '!!!!!!!!!!!!!!!!! attr_dir ===================== ', attr_dir

for f in attr_files:
fl, ext = os.path.splitext(f)

if ext == '.tif':
count_ts += 1
except Exception:
pass

# print '!!!!!!!!!!!!!!!!! getCountTs ===================== ', count_ts

return count_ts
4 changes: 2 additions & 2 deletions src/core/get_coordinate_aoi.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def get_coord_aoi(doc):
if error:
inner_coord, error = get_coord_placemark_polygon_innerboundaryIs(doc)

# print '!!!!!!!!!!!!!!!! TMP outer_coord ======================== ', outer_coord
# print '!!!!!!!!!!!!!!!! TMP inner_coord ======================== ', inner_coord
print '!!!!!!!!!!!!!!!! TMP outer_coord ======================== ', outer_coord
print '!!!!!!!!!!!!!!!! TMP inner_coord ======================== ', inner_coord

return outer_coord, inner_coord

Expand Down
181 changes: 92 additions & 89 deletions src/customers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
validation_kml, is_calculation_aoi, get_info_window,
create_new_calculations_aoi, createUploadTimeSeriesResults)
from core.utils import handle_uploaded_file, get_files_dirs, get_list_lutfiles
from core.functions_customer import getResultDirectory, getTsResultDirectory
from core.functions_customer import getResultDirectory, getTsResultDirectory, getCountTs
from gsi.settings import (BASE_DIR, GOOGLE_MAP_ZOOM, MEDIA_ROOT,
TMP_PATH, DAFAULT_LAT, DAFAULT_LON, PNG_DIRECTORY, PNG_PATH,
PROJECTS_PATH, KML_DIRECTORY, KML_PATH, ATTRIBUTES_NAME, FTP_PATH,
Expand Down Expand Up @@ -1610,69 +1610,69 @@ def getAttributeUnits(user, show_file):
return attribute_name, units


def getResultDirectory(dataset, shelfdata):
dirs_list = []
# is_ts = dataset.is_ts
# def getResultDirectory(dataset, shelfdata):
# dirs_list = []
# # is_ts = dataset.is_ts

try:
project_directory = os.path.join(PROJECTS_PATH, dataset.results_directory)
root, dirs, files = os.walk(project_directory).next()
dirs.sort()
# try:
# project_directory = os.path.join(PROJECTS_PATH, dataset.results_directory)
# root, dirs, files = os.walk(project_directory).next()
# dirs.sort()

for sd in shelfdata:
if str(sd.root_filename) in dirs:
dirs_list.append(sd)
# for sd in shelfdata:
# if str(sd.root_filename) in dirs:
# dirs_list.append(sd)

# if 'TS_' in dataset.results_directory:
# for dy in dirs:
# dirs_list.append(dy)
# is_ts = True
# else:
# for sd in shelfdata:
# if str(sd.root_filename) in dirs:
# dirs_list.append(sd)
except Exception, e:
print '----->>> Exception getResultDirectory ========================= ', e
pass
# # if 'TS_' in dataset.results_directory:
# # for dy in dirs:
# # dirs_list.append(dy)
# # is_ts = True
# # else:
# # for sd in shelfdata:
# # if str(sd.root_filename) in dirs:
# # dirs_list.append(sd)
# except Exception, e:
# print '----->>> Exception getResultDirectory ========================= ', e
# pass

# print '!!!!!!!!!!!!!!!!!!!! DIRS LIST ========================= ', dirs_list
# print '!!!!!!!!!!!!!!!!!!!! TS ========================= ', is_ts
# # print '!!!!!!!!!!!!!!!!!!!! DIRS LIST ========================= ', dirs_list
# # print '!!!!!!!!!!!!!!!!!!!! TS ========================= ', is_ts

return dirs_list
# return dirs_list


def getTsResultDirectory(dataset):
dirs_list = []
shelf_data = dataset.shelf_data
# def getTsResultDirectory(dataset):
# dirs_list = []
# shelf_data = dataset.shelf_data

try:
project_directory = os.path.join(PROJECTS_PATH, dataset.results_directory)
root, dirs, files = os.walk(project_directory).next()
dirs.sort()
# try:
# project_directory = os.path.join(PROJECTS_PATH, dataset.results_directory)
# root, dirs, files = os.walk(project_directory).next()
# dirs.sort()

# print '!!!!!!!!!!!! project_directory ======================= ', project_directory
# print '!!!!!!!!!!!! DIRS ======================= ', dirs
# # print '!!!!!!!!!!!! project_directory ======================= ', project_directory
# # print '!!!!!!!!!!!! DIRS ======================= ', dirs

for d in dirs:
name = '{0} {1}'.format(shelf_data, d)
dirs_list.append(name)
# for d in dirs:
# name = '{0} {1}'.format(shelf_data, d)
# dirs_list.append(name)

# if 'TS_' in dataset.results_directory:
# for dy in dirs:
# dirs_list.append(dy)
# is_ts = True
# else:
# for sd in shelfdata:
# if str(sd.root_filename) in dirs:
# dirs_list.append(sd)
except Exception, e:
print '----->>> Exception getTsResultDirectory ========================= ', e
pass
# # if 'TS_' in dataset.results_directory:
# # for dy in dirs:
# # dirs_list.append(dy)
# # is_ts = True
# # else:
# # for sd in shelfdata:
# # if str(sd.root_filename) in dirs:
# # dirs_list.append(sd)
# except Exception, e:
# print '----->>> Exception getTsResultDirectory ========================= ', e
# pass

# print '!!!!!!!!!!!!!!!!!!!! DIRS LIST ========================= ', dirs_list
# print '!!!!!!!!!!!!!!!!!!!! TS ========================= ', is_ts
# # print '!!!!!!!!!!!!!!!!!!!! DIRS LIST ========================= ', dirs_list
# # print '!!!!!!!!!!!!!!!!!!!! TS ========================= ', is_ts

return dirs_list
# return dirs_list


def getDataSet(ds_id, data_set):
Expand Down Expand Up @@ -1875,54 +1875,54 @@ def createTimeSeriesResults(aoi, file_in, file_out):
pass


def getCountTs(dataset, shd):
# print '!!!!!!!!!!!!!!!!! SHD ===================== ', shd
# def getCountTs(dataset, shd):
# # print '!!!!!!!!!!!!!!!!! SHD ===================== ', shd

is_ts = dataset.is_ts
count_ts = 0
# is_ts = dataset.is_ts
# count_ts = 0

path_cur_proj = dataset.results_directory
path_to_proj = os.path.join(PROJECTS_PATH, path_cur_proj)
# path_cur_proj = dataset.results_directory
# path_to_proj = os.path.join(PROJECTS_PATH, path_cur_proj)

# print '!!!!!!!!!!!!!!!!! path_to_proj ===================== ', path_to_proj
# # print '!!!!!!!!!!!!!!!!! path_to_proj ===================== ', path_to_proj

try:
if os.path.exists(path_to_proj):
pr_root, pr_dirs, pr_files = os.walk(path_to_proj).next()
pr_dirs.sort()
# try:
# if os.path.exists(path_to_proj):
# pr_root, pr_dirs, pr_files = os.walk(path_to_proj).next()
# pr_dirs.sort()

# print '!!!!!!!!!!!!!!!!! pr_dirs ===================== ', pr_dirs
# # print '!!!!!!!!!!!!!!!!! pr_dirs ===================== ', pr_dirs


for d in pr_dirs:
# print '!!!!!!!!!!!!!!!!! d ===================== ', d
# print '!!!!!!!!!!!!!!!!! IN SHD ===================== ', shd
# print '!!!!!!!!!!!!!!!!! d in shd ===================== ', d in shd
if d in shd:
path_to_subdir = os.path.join(path_to_proj, d)
sub_root, sub_dirs, sub_files = os.walk(path_to_subdir).next()
sub_dirs.sort()
# for d in pr_dirs:
# # print '!!!!!!!!!!!!!!!!! d ===================== ', d
# # print '!!!!!!!!!!!!!!!!! IN SHD ===================== ', shd
# # print '!!!!!!!!!!!!!!!!! d in shd ===================== ', d in shd
# if d in shd:
# path_to_subdir = os.path.join(path_to_proj, d)
# sub_root, sub_dirs, sub_files = os.walk(path_to_subdir).next()
# sub_dirs.sort()

# print '!!!!!!!!!!!!!!!!! path_to_subdir ===================== ', path_to_subdir
# # print '!!!!!!!!!!!!!!!!! path_to_subdir ===================== ', path_to_subdir

for sd in sub_dirs:
attr_dir = os.path.join(path_to_subdir, sd)
attr_root, attr_dirs, attr_files = os.walk(attr_dir).next()
attr_files.sort()
# for sd in sub_dirs:
# attr_dir = os.path.join(path_to_subdir, sd)
# attr_root, attr_dirs, attr_files = os.walk(attr_dir).next()
# attr_files.sort()

# print '!!!!!!!!!!!!!!!!! attr_dir ===================== ', attr_dir
# # print '!!!!!!!!!!!!!!!!! attr_dir ===================== ', attr_dir

for f in attr_files:
fl, ext = os.path.splitext(f)
# for f in attr_files:
# fl, ext = os.path.splitext(f)

if ext == '.tif':
count_ts += 1
except Exception:
pass
# if ext == '.tif':
# count_ts += 1
# except Exception:
# pass

# print '!!!!!!!!!!!!!!!!! getCountTs ===================== ', count_ts
# # print '!!!!!!!!!!!!!!!!! getCountTs ===================== ', count_ts

return count_ts
# return count_ts


# def get_count_color():
Expand Down Expand Up @@ -4453,9 +4453,11 @@ def files_lister(request):
select_attr = []
upload_data = data_post.lists()

# print '!!!!!!!!!! UPLOAD DATA ================== ', upload_data

for item in upload_data:
# print '!!!!!!!!!! item 0 ================== ', item[0]
# print '!!!!!!!!!! item 1 ================== ', item[1]
# print '!!!!!!!!!! ITEM 1 ================== ', item[1]

if 'upload-file' in item:
upload_fl = item[1][0]
Expand All @@ -4464,10 +4466,11 @@ def files_lister(request):
select_stat = item[1][0]

if 'select-attr' in item:
tmp_list = item[1]
select_attr = item[1]
# tmp_list = item[1]

for n in tmp_list:
select_attr.append(n.split('_')[0])
# for n in tmp_list:
# select_attr.append(n.split('_')[0])

# print '!!!!!!!!!!!!!!!! ATTR LIST ============================ ', select_attr

Expand Down

0 comments on commit e78eead

Please sign in to comment.