Skip to content

Commit

Permalink
Merge pull request #1071 from linea-it/develop
Browse files Browse the repository at this point in the history
v0.20.2
  • Loading branch information
linea-relmanager authored Feb 2, 2018
2 parents 3794774 + 6234cc3 commit 1cebd10
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 30 deletions.
6 changes: 3 additions & 3 deletions api/product/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from urllib.parse import urljoin
from django.contrib.auth.models import User
import humanize
from astropy.table import Table
from astropy.table import Table as asTable
from django.conf import settings
from django.contrib.auth.models import User
from django.core.mail import EmailMessage
Expand Down Expand Up @@ -95,7 +95,7 @@ def get_columns(self, row):

return columns

def table_to_csv(self, product_id, table, export_dir, user_id, schema=None, database=None, filters=None):
def table_to_csv_by_id(self, product_id, table, export_dir, user_id, schema=None, database=None, filters=None):
"""
Le uma tabela no banco de Catalogos e cria um csv com o resultado.
OBS: NAO recomendada para tabelas grandes. por que neste metodo todos as linhas
Expand Down Expand Up @@ -202,7 +202,7 @@ def csv_to_fits(self, csv, fits):

try:

t = Table.read(csv, format='ascii.csv')
t = asTable.read(csv, format='ascii.csv')

t.write(fits)

Expand Down
74 changes: 47 additions & 27 deletions api/product/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,45 +266,65 @@ def export_target_by_filter(product_id, filetypes, user_id, filter_id=None, cuto
filetype = filetype.strip()

if filetype == "csv":
logger.info("Starting Task target_to_csv")

# Task To CSV
header.append(
export_target_to_csv.s(
product.pk,
product.table.tbl_database,
product.table.tbl_schema,
product.table.tbl_name,
conditions,
export_dir,
user_id
)
export.table_to_csv_by_id(
product_id=product.pk,
database=product.table.tbl_database,
schema=product.table.tbl_schema,
table=product.table.tbl_name,
filters=conditions,
export_dir=export_dir,
user_id=user_id
)

logger.info("Finished Task target_to_csv")


elif filetype == "fits":
# Task To Fits
header.append(
export_target_to_fits.s(
product.pk,
product.table.tbl_database,
product.table.tbl_schema,
product.table.tbl_name,
conditions,
export_dir,
user_id
)
logger.info("Starting Task target_to_fits")

# Primeiro deve gerar um csv para depois converter para fits.
csvfile = export.table_to_csv_by_id(
product_id=product.pk,
database=product.table.tbl_database,
schema=product.table.tbl_schema,
table=product.table.tbl_name,
filters=conditions,
export_dir=export_dir,
user_id=user_id
)

logger.info("Csv File: %s" % csvfile)

fname, extension = os.path.splitext(csvfile)

fitsfile = "%s.fits" % fname
logger.debug("FITS FILE %s" % fitsfile)

fits = export.csv_to_fits(
csv=csvfile,
fits=fitsfile
)

logger.info("Finished Task target_to_fits")


# Cutouts
if cutoutjob_id not in [None, "", False, "false", "False", 0]:
header.append(
export_cutoutjob.s(
cutoutjob_id,
export_dir))
export_cutoutjob(cutoutjob_id, export_dir)

logger.debug("Teste: %s" % cutoutjob_id)


callback = export_create_zip.s(user.pk, product.prd_display_name, export_dir)
# Cria um arquivo zip com todos os arquivos gerados pelo export.
url = export.create_zip(export_dir)

result = chord(header)(callback)
# Notifica o Usuario sobre o Download.
export.notify_user_export_success(user.pk, product.prd_display_name, url)

result.get()

except Exception as e:
logger.error(e)
Expand Down

0 comments on commit 1cebd10

Please sign in to comment.