by shigemk2

当面は技術的なことしか書かない

Redashのrefresh.pyのやつ

  • APIをキックしてRedashのクエリデータをリフレッシュして出力するやつ 以下の順番でAPIが実行されている
    1. refresh
    2. job
    3. results
  • こちらではJSONが出力されるようになっているけど3のresultsでCSV出力も可能
    • 3のresultsAPIではresult idがキーになっており、GET /api/queries/query_id/results.csv?api_key=xxxxxxxxx で落とせるAPI(クエリの画面から拾えるやつ)とは叩いているAPIが違う
    • GET /api/queries/query_id/results.csv

Redash Refresh API usage example with parameters Raw · GitHub

fish shell EOF

確認バージョン: 2.6.0-753-g9104c107

fishでbashのEOFなことはいまだに出来ないので、なんとかしてなんとかしたい

echo "\
  foo
  " | nc

これではEOFで追記的なリダイレクトはできないから。

(Perlのワンライナーは代替にならない)

Add support for "here documents" · Issue #540 · fish-shell/fish-shell · GitHub

Unix Shells: Bash, Fish, Ksh, Tcsh, Zsh - Hyperpolyglot

awscli 1.16.56

今回は多い

  • api-change:rds: Update rds command to latest version
  • api-change:transcribe: Update transcribe command to latest version
  • api-change:pinpoint: Update pinpoint command to latest version
  • api-change:s3: Update s3 command to latest version
  • api-change:redshift: Update redshift command to latest version
  • api-change:dms: Update dms command to latest version
  • api-change:codebuild: Update codebuild command to latest version
  • api-change:route53resolver: Update route53resolver command to latest version
  • api-change:s3control: Update s3control command to latest version
  • api-change:directconnect: Update directconnect command to latest version
  • api-change:comprehend: Update comprehend command to latest version
  • api-change:ram: Update ram command to latest version
  • api-change:sms-voice: Update sms-voice command to latest version
  • api-change:iam: Update iam command to latest version
  • api-change:ecs: Update ecs command to latest version

Release 1.16.56 · aws/aws-cli · GitHub

awscli 1.16.55

  • api-change:autoscaling: Update autoscaling command to latest version
  • api-change:ec2: Update ec2 command to latest version
  • api-change:resource-groups: Update resource-groups command to latest version
  • api-change:sagemaker: Update sagemaker command to latest version
  • api-change:mediatailor: Update mediatailor command to latest version
  • api-change:sns: Update sns command to latest version
  • api-change:servicecatalog: Update servicecatalog command to latest version

Release 1.16.55 · aws/aws-cli · GitHub

Pandasで実現したいサンプル

SELECT name,
       COALESCE(ROUND((test_x / test_y) * 100, 2), 0) as percentage
FROM
  (SELECT name,
          TYPE,
          text_x
   FROM INPUT
   WHERE TYPE = 'alpha') d1
LEFT OUTER JOIN
  (SELECT name,
          TYPE,
          text_y
   FROM INPUT
   WHERE TYPE = 'beta') d2 ON d1.name = d2.name

こういうクエリをPandasで実現したい

#coding: utf-8
import pandas as pd
import numpy as np
input_df = pd.read_csv('input.csv')
d1 = input_df[input_df['type'] == 'alpha']
d2 = input_df[input_df['type'] == 'beta']
merged_df = pd.merge(d1, d2, on='name')
dfp = pd.DataFrame(merged_df['name'], columns=['name'])
dfp['percentage'] = merged_df['test_x'].div(merged_df['test_y']).mul(100).round(2).replace([np.inf, -np.inf], 0)
# dfp.to_csv('./output.csv', mode='w', index=False, header=True, encoding="utf-8")

redash-dynamic-query

import_classは assert True にしてるからあんまり意味がなくて、test_redash_dynamic_queryのほうは、bindのパラメータをいくつかずらしてクエリが正しく生成されることを確認している

$ python -m unittest tests.import_class
$ python -m unittest tests.test_redash_dynamic_query

これだけ実行してもテストは走らない謎

$ python -m unittest tests