Skip to content

Commit

Permalink
Merge pull request #970 from linea-it/develop
Browse files Browse the repository at this point in the history
v0.16.1
  • Loading branch information
glaubervila authored Dec 15, 2017
2 parents 5bf489d + 2699083 commit 7d191ea
Show file tree
Hide file tree
Showing 23 changed files with 277 additions and 103 deletions.
43 changes: 42 additions & 1 deletion api/coadd/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import os
from urllib.parse import urljoin

from common.models import Filter

# Create your views here.
class ReleaseViewSet(viewsets.ModelViewSet):
"""
Expand Down Expand Up @@ -160,13 +162,52 @@ def get_fits_by_tilename(request):

result = list()


ordered_filters = dict({})
filters = Filter.objects.all().order_by('lambda_min')
order = 0
for f in filters:
ordered_filters[f.filter] = order
order += 1

ordered_filters['det'] = order
order += 1
ordered_filters['irg'] = order

for filename in files:

file_source = urljoin(data_source, filename)

extension = os.path.splitext(filename)[1]

flr = None
ord = None

# Se for um arquivo de imagem descobrir o filtro
if extension == '.fz':
parts = filename.split('_')
flr = parts[2].strip('_')
flr = flr.split('.')[0]
try:
ord = ordered_filters[flr]
except:
pass

if extension == '.tiff':
parts = filename.split('_')
flr = parts[2].strip('_')
flr = flr.split('.')[0]
try:
ord = ordered_filters[flr]
except:
pass


result.append(dict({
'filename': filename,
'file_source': file_source
'file_source': file_source,
'filter': flr,
'order': ord
}))


Expand Down
1 change: 0 additions & 1 deletion api/dri/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
router.register(r'userquery_table', userquery_views.TableViewSet)
router.register(r'userquery_validate', userquery_views.QueryValidate, base_name='validate_query')
router.register(r'userquery_preview', userquery_views.QueryPreview, base_name='preview_query')
router.register(r'userquery_create_table', userquery_views.CreateTable, base_name='create_table')
router.register(r'userquery_property', userquery_views.TableProperties, base_name='table')
router.register(r'userquery_target', userquery_views.TargetViewerRegister, base_name='target_viewer_register')

Expand Down
51 changes: 37 additions & 14 deletions api/lib/sqlalchemy_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ def get_create_auto_increment_column(self, table, column_name, schema=None):

return sql

def get_table_name(self, table):
return table.upper()

def get_schema_name(self, schema):
return schema.upper()


class DBSqlite:
def __init__(self, db):
self.db = db
Expand All @@ -97,6 +104,12 @@ def get_raw_sql_limit(self, line_number):
def get_table_properties(self, table, schema=None):
raise("Implement this method")

def get_table_name(self, table):
return table

def get_schema_name(self, schema):
return schema


# classe generica - nao ligada a este problema
class DBBase:
Expand Down Expand Up @@ -171,27 +184,33 @@ def get_table_columns(self, table, schema=None):
return [value['name'] for value in self.inspect.get_columns(table, schema)]

def get_table_properties(self, table, schema=None):
# Each database has its own rules related to name conventions. Here we
# suppose that schema and tables names are created without quotes
table = self.database.get_table_name(table)
if schema:
schema = self.database.get_schema_name(schema)

properties = dict()

sql = self.database.get_raw_sql_column_properties(table, schema=schema)
columns = self.fetchall_dict(sql)
columns.sort(key=lambda k: k['column_name'])
properties['columns'] = columns

sql = self.database.get_raw_sql_table_rows(table, schema=schema)
with self.engine.connect() as con:
queryset = con.execute(sql)
properties['table_rows'] = queryset.fetchone()[0]

sql = self.database.get_raw_sql_size_table_bytes(table, schema=schema)
with self.engine.connect() as con:
queryset = con.execute(sql)
properties['table_bytes'] = queryset.fetchone()[0]

sql = self.database.get_raw_sql_number_columns(table, schema=schema)
with self.engine.connect() as con:
queryset = con.execute(sql)
properties['table_num_columns'] = queryset.fetchone()[0]
# sql = self.database.get_raw_sql_table_rows(table, schema=schema)
# with self.engine.connect() as con:
# queryset = con.execute(sql)
# properties['table_rows'] = queryset.fetchone()[0]
#
# sql = self.database.get_raw_sql_size_table_bytes(table, schema=schema)
# with self.engine.connect() as con:
# queryset = con.execute(sql)
# properties['table_bytes'] = queryset.fetchone()[0]
#
# sql = self.database.get_raw_sql_number_columns(table, schema=schema)
# with self.engine.connect() as con:
# queryset = con.execute(sql)
# properties['table_num_columns'] = queryset.fetchone()[0]

return properties

Expand All @@ -213,6 +232,10 @@ def get_count(self, table, schema=None):
return result.fetchone()[0]

def table_exists(self, table, schema=None):
table = self.database.get_table_name(table)
if schema:
schema = self.database.get_schema_name(schema)

# Desabilitar os warnings na criacao da tabela
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=sa_exc.SAWarning)
Expand Down
20 changes: 20 additions & 0 deletions api/product/migrations/0006_auto_20171213_1348.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2017-12-13 13:48
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('product', '0005_auto_20171212_1723'),
]

operations = [
migrations.AlterField(
model_name='product',
name='prd_is_public',
field=models.BooleanField(default=False, help_text='Is Public default False', verbose_name='Is Public'),
),
]
4 changes: 2 additions & 2 deletions api/userquery/create_table_as.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ def _create_table_by_job_id(self):
self.is_table_successfully_created = True

release = Release.objects.get(pk=self.release_id)
table_properties = db.get_table_properties(self.table_name.upper(), schema=self.schema)
count = db.get_count(self.table_name, schema=self.schema)
self.table = Table(table_name=self.table_name,
display_name=self.job.display_name,
owner=self.job.owner,
schema=self.schema,
release=release,
tbl_num_objects=table_properties['table_rows'])
tbl_num_objects=count)

self.table.save()
except Exception as e:
Expand Down
20 changes: 20 additions & 0 deletions api/userquery/migrations/0006_auto_20171214_0545.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2017-12-14 05:45
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('userquery', '0005_table_tbl_num_objects'),
]

operations = [
migrations.AlterField(
model_name='query',
name='name',
field=models.CharField(max_length=128, verbose_name='Name'),
),
]
20 changes: 20 additions & 0 deletions api/userquery/migrations/0007_auto_20171214_0625.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2017-12-14 06:25
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('userquery', '0006_auto_20171214_0545'),
]

operations = [
migrations.AlterField(
model_name='table',
name='display_name',
field=models.CharField(max_length=128, verbose_name='Display name'),
),
]
4 changes: 2 additions & 2 deletions api/userquery/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Query(models.Model):
# the same user can't have repeated names.
name = models.CharField(
max_length=128, unique=True, null=False, verbose_name='Name')
max_length=128, unique=False, null=False, verbose_name='Name')
description = models.CharField(
max_length=256, null=True, blank=True, verbose_name='Description')
owner = models.ForeignKey(
Expand Down Expand Up @@ -72,7 +72,7 @@ class Table(models.Model):
table_name = models.CharField(
max_length=128, null=False, unique=True, verbose_name='Name')
display_name = models.CharField(
max_length=128, null=False, unique=True, verbose_name='Display name')
max_length=128, null=False, unique=False, verbose_name='Display name')
owner = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
Expand Down
4 changes: 2 additions & 2 deletions api/userquery/serializers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.db import models
from rest_framework import serializers
from .models import *
from product.models import Product
Expand Down Expand Up @@ -44,8 +45,7 @@ class Meta:
class TableSerializer(serializers.ModelSerializer):
owner = serializers.ReadOnlyField(source='owner.username')
id = serializers.ReadOnlyField()
product_id = serializers.PrimaryKeyRelatedField(
queryset=Product.objects.all(), many=False)
product_id = serializers.ReadOnlyField(source='product.id')

class Meta:
model = Table
Expand Down
Loading

0 comments on commit 7d191ea

Please sign in to comment.