Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
GeoInt_SIDT
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mario Chirinos Colunga
GeoInt_SIDT
Commits
639db3e9
Commit
639db3e9
authored
Feb 13, 2019
by
Ulises Morales Ramírez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reports dynamic
parent
4d330260
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
413 additions
and
293 deletions
+413
-293
__init__.py
GeoInt_SIDT/__init__.py
+6
-0
celery.py
GeoInt_SIDT/celery.py
+16
-0
tasks.py
GeoInt_SIDT/tasks.py
+28
-0
scripts.js
reports/static/reports/js/scripts.js
+46
-0
Reports.html
reports/templates/Reports.html
+239
-266
tests.py
reports/tests.py
+14
-0
urls.py
reports/urls.py
+1
-0
views.py
reports/views.py
+63
-27
No files found.
GeoInt_SIDT/__init__.py
View file @
639db3e9
# coding=utf-8
from
__future__
import
absolute_import
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from
celery
import
app
as
celery_app
\ No newline at end of file
GeoInt_SIDT/celery.py
0 → 100644
View file @
639db3e9
# coding=utf-8
from
__future__
import
absolute_import
,
unicode_literals
from
celery
import
Celery
app
=
Celery
(
'GeoInt_SIDT'
,
broker
=
'amqp://'
,
backend
=
'amqp://'
,
include
=
[
'GeoInt_SIDT.tasks'
])
# Optional configuration, see the application user guide.
app
.
conf
.
update
(
result_expires
=
3600
,
)
if
__name__
==
'__main__'
:
app
.
start
()
\ No newline at end of file
GeoInt_SIDT/tasks.py
0 → 100644
View file @
639db3e9
# coding=utf-8
from
__future__
import
absolute_import
,
unicode_literals
from
.celery
import
app
@
app
.
task
def
add
(
x
,
y
):
if
x
>
y
:
return
"x es mayor"
elif
x
<
y
:
return
"y es mayor"
else
:
return
"son iguales"
@
app
.
task
def
mul
(
x
,
y
):
return
x
*
y
@
app
.
task
def
xsum
(
numbers
):
return
sum
(
numbers
)
@
app
.
task
def
names
(
name
):
return
(
name
)
\ No newline at end of file
reports/static/reports/js/scripts.js
0 → 100644
View file @
639db3e9
function
openmodal
(
info
)
{
info2
=
info
.
split
(
";"
);
$
(
"#myModal"
).
modal
();
$
(
"#log_info"
).
append
(
info2
);
}
function
refresh
()
{
$
.
ajax
({
dataType
:
"json"
,
url
:
'Reload'
,
success
:
function
(
data
)
{
$
.
each
(
data
,
function
(
key
,
val
)
{
console
.
log
(
key
+
" = "
+
val
.
purchase_id
+
""
+
val
.
progress
)
if
(
val
.
progress
!=
100
)
{
$
(
'#progress_bar'
+
val
.
purchase_id
+
''
).
attr
(
"aria-valuenow"
,
val
.
progress
);
$
(
'#progress_bar'
+
val
.
purchase_id
+
''
).
attr
(
'style'
,
'width:'
+
val
.
progress
+
'%'
);
document
.
getElementById
(
'progess_value'
+
val
.
purchase_id
).
innerHTML
=
val
.
progress
+
' %'
;
$
(
'#progress_bar'
+
val
.
purchase_id
+
''
).
attr
(
"class"
,
"progress-bar progress-bar-warning progress-bar-striped active"
);
$
(
'#view_report'
+
val
.
purchase_id
+
''
).
attr
(
'disabled'
,
'false'
);
$
(
'#action_buttons'
+
val
.
purchase_id
+
''
).
attr
(
"class"
,
"hidden"
);
$
(
'#main_progess'
+
val
.
purchase_id
+
''
).
removeClass
(
"hidden"
);
$
(
'#main_progess'
+
val
.
purchase_id
+
''
).
attr
(
"class"
,
"progress"
);
}
else
{
$
(
'#progress_bar'
+
val
.
purchase_id
+
''
).
attr
(
"class"
,
"progress-bar progress-bar-success progress-bar-striped"
);
$
(
'#progress_bar'
+
val
.
purchase_id
+
''
).
attr
(
"aria-valuenow"
,
val
.
progress
);
$
(
'#progress_bar'
+
val
.
purchase_id
+
''
).
attr
(
'style'
,
'width:'
+
val
.
progress
+
'%'
);
document
.
getElementById
(
'progess_value'
+
val
.
purchase_id
).
innerHTML
=
val
.
progress
+
' %'
;
$
(
'#view_report'
+
val
.
purchase_id
+
''
).
removeAttr
(
"disabled"
);
$
(
'#view_report'
+
val
.
purchase_id
+
''
).
attr
(
"href"
,
"{{ BASE_URL }}/reports/T15QZD_sclData/"
+
val
.
purchase_id
);
$
(
'#main_progess'
+
val
.
purchase_id
+
''
).
attr
(
"class"
,
"hidden"
);
$
(
'#action_buttons'
+
val
.
purchase_id
+
''
).
removeClass
(
"hidden"
);
}
});
}
});
};
$
(
function
()
{
refresh
();
var
int
=
setInterval
(
"refresh()"
,
1000
);
});
$
(
function
()
{
$
(
'#reportPage'
).
show
();
});
\ No newline at end of file
reports/templates/Reports.html
View file @
639db3e9
This diff is collapsed.
Click to expand it.
reports/tests.py
View file @
639db3e9
# -*- coding: utf-8 -*-
from
__future__
import
absolute_import
from
__future__
import
unicode_literals
from
django.test
import
TestCase
# Create your tests here.
from
celery
import
shared_task
@
shared_task
def
add
(
x
,
y
):
return
x
+
y
@
shared_task
def
mul
(
x
,
y
):
return
x
*
y
@
shared_task
def
xsum
(
numbers
):
return
sum
(
numbers
)
reports/urls.py
View file @
639db3e9
...
...
@@ -7,5 +7,6 @@ urlpatterns = [
url
(
r'^(?P<report>[\w\-]+)/(?P<purchase_id>(\d+))$'
,
views
.
report_L2ASCL
,
name
=
'report'
),
url
(
r'^$'
,
views
.
Reports
,
name
=
'reports'
),
url
(
r'^Reload$'
,
views
.
Reload
,
name
=
'Reload'
),
]
reports/views.py
View file @
639db3e9
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
import
io
import
json
import
os
# Create your views here.
from
collections
import
OrderedDict
from
django.core.paginator
import
Paginator
from
django.http
import
FileResponse
from
reportlab.pdfgen
import
canvas
from
django.shortcuts
import
render
from
django.http
import
HttpResponse
,
Http404
from
django.shortcuts
import
render
,
render_to_response
# Create your views here.
from
collections
import
OrderedDict
import
json
import
os
from
GeoInt_SIDT.tasks
import
add
from
catalog.models
import
Purchase
from
GeoInt_SIDT.tasks
import
*
# -------------------------------------------------------------------------------
from
reportlab.pdfgen
import
canvas
from
GeoInt_SIDT
import
settings
from
catalog.models
import
CartProduct
,
Purchase
,
Search
########### lee archivo de configuración ################
dirname
=
os
.
path
.
dirname
(
__file__
)
...
...
@@ -28,13 +25,14 @@ with open(configfile, 'r') as f:
USERS_PATH
=
config
[
'PATHS'
][
'PATH_USERS'
]
###########################################################
def
report_L2ASCL
(
request
,
report
,
purchase_id
):
#image_path =USERS_PATH + request.user.email+"/"+purchase_id+"/"+"out/T15QZD/TCI/"
image_path
=
request
.
user
.
email
+
"/"
+
purchase_id
+
"/"
+
"out/T15QZD/TCI/"
with
open
(
USERS_PATH
+
request
.
user
.
email
+
"/"
+
purchase_id
+
"/"
+
report
+
".json"
)
as
f
:
def
report_L2ASCL
(
request
,
report
,
purchase_id
):
#
image_path =USERS_PATH + request.user.email+"/"+purchase_id+"/"+"out/T15QZD/TCI/"
image_path
=
request
.
user
.
email
+
"/"
+
purchase_id
+
"/"
+
"out/T15QZD/TCI/"
with
open
(
USERS_PATH
+
request
.
user
.
email
+
"/"
+
purchase_id
+
"/"
+
report
+
".json"
)
as
f
:
json_data
=
OrderedDict
(
json
.
load
(
f
))
graphData
=
dict
()
graphData
[
'type'
]
=
"line"
...
...
@@ -46,7 +44,6 @@ def report_L2ASCL(request, report,purchase_id):
labels
=
set
()
for
d
in
json_data
:
labels
|=
set
(
json_data
[
d
]
.
keys
())
print
(
labels
)
labels
.
remove
(
'date'
)
labelNames
=
[
...
...
@@ -79,7 +76,7 @@ def report_L2ASCL(request, report,purchase_id):
# print(settings.BASE_URL)
# graphData['options']['responsive']=True
# graphData['options']['maintainAspectRatio']=False
# print(json.dumps(graphData).encode("utf-8"))
# print(json.dumps(graphData).encode("utf-8"))
return
render
(
request
,
'L2ASCL_data.html'
,
{
"graphData"
:
json
.
dumps
(
graphData
),
"report_name"
:
report
,
"IMAGE_PATH"
:
image_path
,
'dafaultLabel'
:
defaultLabel
,
'defaultDataSet'
:
defaultDataset
})
...
...
@@ -88,9 +85,11 @@ def report_L2ASCL(request, report,purchase_id):
def
Reports
(
request
):
progress
=
0
productList
=
[]
productList
=
[]
size
=
0
product_list
=
Purchase
.
objects
.
values
(
'id'
,
'productList'
,
'aggreg_date'
,
'search__clouds'
,
'search__startDate'
,
'search__endDate'
,
'search__process_id__name'
)
.
filter
(
user_id
=
request
.
user
.
id
,
purchased
=
1
)
product_list
=
Purchase
.
objects
.
values
(
'id'
,
'productList'
,
'aggreg_date'
,
'search__clouds'
,
'search__startDate'
,
'search__endDate'
,
'search__process_id__name'
)
.
filter
(
user_id
=
request
.
user
.
id
,
purchased
=
1
)
for
producto
in
product_list
:
log_info
=
USERS_PATH
+
request
.
user
.
email
+
"/"
+
str
(
producto
[
'id'
])
+
"/L2ASCL_AreaProcessing.log"
...
...
@@ -108,21 +107,19 @@ def Reports(request):
if
'Finalizing...'
in
open
(
log_info
)
.
read
():
progress
=
100
with
open
(
log_info
,
'r'
)
as
myfile
:
log
=
myfile
.
read
()
.
replace
(
'
\n
'
,
''
)
for
p
in
json
.
loads
(
producto
[
'productList'
]):
size
=
size
+
float
(
p
[
'info'
][
'size'
][:
-
3
])
if
size
>
1000
:
size2
=
size
/
1000
final_size
=
str
(
round
(
size2
,
2
))
+
" GB"
size2
=
size
/
1000
final_size
=
str
(
round
(
size2
,
2
))
+
" GB"
else
:
final_size
=
str
(
round
(
size
,
2
))
+
" MB"
final_size
=
str
(
round
(
size
,
2
))
+
" MB"
productList
.
append
({
"process"
:
producto
[
'search__process_id__name'
],
"process"
:
producto
[
'search__process_id__name'
],
"purchase_date"
:
producto
[
'aggreg_date'
],
"startDate"
:
producto
[
'search__startDate'
],
"endDate"
:
producto
[
'search__endDate'
],
...
...
@@ -140,6 +137,45 @@ def Reports(request):
page
=
request
.
GET
.
get
(
'page'
)
productList
=
paginator
.
get_page
(
page
)
return
render
(
request
,
'Reports.html'
,
{
"productList"
:
productList
})
return
render
(
request
,
'Reports.html'
,
{
"productList"
:
productList
})
# ------------------------------------------------------------------------
def
Reload
(
request
):
if
request
.
is_ajax
():
progress
=
0
productList2
=
[]
product_list
=
Purchase
.
objects
.
values
(
'id'
,
'productList'
,
'aggreg_date'
,
'search__clouds'
,
'search__startDate'
,
'search__endDate'
,
'search__process_id__name'
)
.
filter
(
user_id
=
request
.
user
.
id
,
purchased
=
1
)
for
producto
in
product_list
:
log_info
=
USERS_PATH
+
request
.
user
.
email
+
"/"
+
str
(
producto
[
'id'
])
+
"/L2ASCL_AreaProcessing.log"
#####################################################
# progress bar #
#####################################################
if
'Linking Products...'
in
open
(
log_info
)
.
read
():
progress
=
20
if
'Merging Images...'
in
open
(
log_info
)
.
read
():
progress
=
40
if
'Deleting Images...'
in
open
(
log_info
)
.
read
():
progress
=
50
if
'Extracting SCL information...'
in
open
(
log_info
)
.
read
():
progress
=
60
if
'Finalizing...'
in
open
(
log_info
)
.
read
():
progress
=
100
productList2
.
append
({
"purchase_id"
:
producto
[
'id'
],
"progress"
:
progress
,
})
return
HttpResponse
(
json
.
dumps
(
productList2
))
else
:
raise
Http404
# ------------------------------------------------------------------------
# def tareas():
# result = add.apply_async((2, 1), countdown=3)
# result.get()
# return render_to_response('reports_table.html', {"result": result.get()})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment