Skip to content

Commit

Permalink
Borrado de código no usado
Browse files Browse the repository at this point in the history
Saca toda la funcionalidad de armado de dump de analytics, la
funcionalidad está provista ahora de manera más robusta por api-gateway.
Saca el endpoint de save() de analytics, el cargado también es hecho por
api-gateway
  • Loading branch information
lucaslavandeira committed Nov 29, 2018
1 parent 4262105 commit b529912
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 305 deletions.

This file was deleted.

37 changes: 0 additions & 37 deletions series_tiempo_ar_api/apps/analytics/tasks.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,9 @@
#! coding: utf-8
import os
import json
import requests
import unicodecsv
from django_rq import job
from django.conf import settings
from django.utils import timezone

from .models import Query
from .utils import kong_milliseconds_to_tzdatetime
from .importer import AnalyticsImporter


@job("default")
def analytics(ids, args_string, ip_address, params, timestamp_milliseconds):
params_json = json.dumps(params)
timestamp = kong_milliseconds_to_tzdatetime(timestamp_milliseconds)
query = Query(ids=ids, args=args_string, ip_address=ip_address, params=params_json, timestamp=timestamp)
query.save()


@job("default", timeout=360)
def export(path=None):
queryset = Query.objects.all()
filepath = path or os.path.join(settings.PROTECTED_MEDIA_DIR, settings.ANALYTICS_CSV_FILENAME)

fields = {
'timestamp': lambda x: timezone.localtime(x.timestamp),
'ip_address': lambda x: x.ip_address,
'ids': lambda x: x.ids,
'params': lambda x: x.params,
}

with open(filepath, 'wb') as f:
writer = unicodecsv.writer(f)
# header
writer.writerow([field for field in fields])
for query in queryset.iterator():

writer.writerow([val(query) for val in fields.values()])


@job('default', timeout=1000)
def import_analytics_from_api_mgmt(limit=1000, requests_lib=requests, import_all=False):
AnalyticsImporter(limit, requests_lib).run(import_all)

This file was deleted.

21 changes: 0 additions & 21 deletions series_tiempo_ar_api/apps/analytics/templates/export.html

This file was deleted.

47 changes: 0 additions & 47 deletions series_tiempo_ar_api/apps/analytics/tests/export_tests.py

This file was deleted.

81 changes: 0 additions & 81 deletions series_tiempo_ar_api/apps/analytics/tests/tests.py

This file was deleted.

48 changes: 0 additions & 48 deletions series_tiempo_ar_api/apps/analytics/tests/view_tests.py

This file was deleted.

4 changes: 0 additions & 4 deletions series_tiempo_ar_api/apps/analytics/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
from django.conf.urls import url
from .views import save, read_analytics, export_analytics

urlpatterns = [
url('^save/$', save, name='save'),
url('^analytics.csv', read_analytics, name='read_analytics'),
url('^export', export_analytics, name='export_analytics'),
]
50 changes: 0 additions & 50 deletions series_tiempo_ar_api/apps/analytics/views.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,2 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import os
import json

import sendfile
from django.http import HttpResponse
from django.conf import settings
from django.views.decorators.csrf import csrf_exempt
from django.contrib.admin.views.decorators import staff_member_required
from django.shortcuts import render

from .tasks import analytics, export


@csrf_exempt
def save(request):
if request.method != 'POST':
return HttpResponse(status=405)

body = json.loads(request.body)
req_data = body.get('request')
if not req_data: # Fatal error
return HttpResponse(status=400)

uri = req_data.get('uri')
if 'admin/' in uri or 'api/' not in uri:
return HttpResponse()

params = req_data.get('querystring')
ids = params.get('ids', 'No especificado')
ip_address = body.get('client_ip')
timestamp = body.get('started_at')
args = req_data.get('request_uri', 'No especificado')

params_start = args.find('?')
if params_start > 0:
args = args[params_start:]
analytics.delay(ids, args, ip_address, params, timestamp)
return HttpResponse()


@staff_member_required
def read_analytics(request):
return sendfile.sendfile(request, os.path.join(settings.PROTECTED_MEDIA_DIR, 'analytics.csv'))


@staff_member_required
def export_analytics(request):
export.delay()
return HttpResponse(render(request, 'export.html'))

0 comments on commit b529912

Please sign in to comment.