Skip to content
This repository has been archived by the owner on Feb 23, 2022. It is now read-only.

Commit

Permalink
fix for hashtag + timeline search
Browse files Browse the repository at this point in the history
  • Loading branch information
ryankicks committed Oct 17, 2015
1 parent a9477e7 commit c4dad84
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
18 changes: 10 additions & 8 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ def get(self, table):
charttype = self.request.get("charttype")
interval = int(self.request.get("interval")) if self.request.get("interval") else SEARCH_DAYS

builder = QueryBuilder(QueryBuilder.GNIP if config.MODE == "gnip" else QueryBuilder.PUBLIC, table, field, charttype, interval)
builder = QueryBuilder(QueryBuilder.GNIP if config.MODE == QueryBuilder.GNIP else QueryBuilder.PUBLIC, table, field, charttype, interval)
query = builder.query()

results = Utils.get_bq().jobs().query(projectId=config.PROJECT_NUMBER, body={'query':query}).execute()
args = builder.c3_args(query, results)

self.response.headers['Content-Type'] = 'application/json'
self.response.out.write(json.dumps(args))

Expand Down Expand Up @@ -384,7 +384,7 @@ def get(self):
start = end - timedelta(days=days)
timeline = g.query(rule, 1, record_callback=None, use_case="timeline", start=start, end=end, count_bucket="day")
timeline = json.loads(timeline)
print timeline
# print timeline

count = 0
for r in timeline["results"]:
Expand Down Expand Up @@ -420,7 +420,7 @@ def post(self):
rule = self.request.get("rule", None)
table_fqdn = self.request.get("table", None)

print table_fqdn
# print table_fqdn

(dataset, table) = Utils.parse_bqid(table_fqdn)
tag = Utils.make_tag(dataset, table)
Expand Down Expand Up @@ -524,6 +524,8 @@ def get(self):
"value" : value
}

print rule_delete

response = rules.delete_rule(rule_delete, **GNIP_RULES_PARAMS)
TABLE_CACHE.clear()

Expand Down Expand Up @@ -612,11 +614,10 @@ def query(self):
self.prefix = ''
col = 'generator.displayName'

col_use = "lower(%s)" % col if unique else col
select = "%s as value, count(*) as count" % col_use
select = "lower(%s) as value, count(*) as count" % col
fromclause = "flatten(%s, %s)" % (self.from_clause, flatten_field) if flatten_field else self.from_clause
time_filter = "DATE_ADD(CURRENT_TIMESTAMP(), -%s, 'DAY')" % (self.interval)
filter = "%s is not null AND %s > %s" % (col_use, created_field, time_filter)
filter = "%s is not null AND %s > %s" % (col, created_field, time_filter)
groupby = "value"
orderby = "count DESC"
limit = 20
Expand All @@ -631,7 +632,7 @@ def query(self):
if self.interval == 1:
create_hour = "CONCAT(STRING(YEAR(TIMESTAMP(t1.%s))), '-', STRING(MONTH(TIMESTAMP(t1.%s))), '-', STRING(DAY(TIMESTAMP(t1.%s))), ' ', LPAD(STRING(HOUR(TIMESTAMP(t1.%s))), 2, '0'), ':00')" % (created_field, created_field, created_field, created_field)

select = "t1.%s, %s AS create_hour" % (select, create_hour)
select = "lower(t1.%s) as value, count(*) as count, %s AS create_hour" % (col, create_hour)
fromclause = "flatten(%s, %s)" % (self.from_clause, flatten_field) if flatten_field else self.from_clause
fromclause = """
%s t1
Expand Down Expand Up @@ -670,6 +671,7 @@ def query(self):
ORDER BY
%s
LIMIT %s""" % (select, fromclause, filter, groupby, orderby, limit)

print query

return query
Expand Down
9 changes: 5 additions & 4 deletions templates/rule_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ <h1>PowerTrack Rules</h1>
<tr>
<th></th>
<th>Rule</th>
<th>
Dataset
<th>Dataset</th>
<th width="40%">HPT JSON

<div class="btn-group pull-right">
<button id="action_group" type="button" class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Action <span class="caret"></span>
Expand All @@ -31,8 +32,8 @@ <h1>PowerTrack Rules</h1>
<li><a href="#" class="rule_delete">Delete</a></li>
</ul>
</div>
</th>
<th width="40%">HPT JSON</th>

</th>
</tr>
</thead>
<tbody id="table_data">
Expand Down
6 changes: 3 additions & 3 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def insert_table(dataset_id, table_id, schema=None):

schema_file = None

if config.MODE == "gnip":
if config.MODE == QueryBuilder.GNIP:
schema_file = "./schema/schema_gnip.json"
else:
schema_file = "./schema/schema_twitter.json"
Expand Down Expand Up @@ -109,8 +109,8 @@ def insert_records(dataset_id, table_id, tweets):

response = Utils.get_bq().tabledata().insertAll(projectId=config.PROJECT_ID, datasetId=dataset_id, tableId=table_id, body=body).execute()

print "insert_records: %s %s %s" % (config.PROJECT_ID, dataset_id, table_id)
print response
# print "insert_records: %s %s %s" % (config.PROJECT_ID, dataset_id, table_id)
# print response

return response

Expand Down

0 comments on commit c4dad84

Please sign in to comment.