我目前正在运行一个查询,该查询运行一个 sum 函数并将这个数字除以。目前我得到的值是 0.0904246741698848 和 1.6419814808335567。我希望将这些小数修剪为小数点后 2 个空格。他们的架构是一个浮点数。这是我的代码。谢谢您的帮助。
#standardSQL
SELECT
Serial,
MAX(createdAt) AS Latest_Use,
SUM(ConnectionTime/3600) as Total_Hours,
COUNT(DISTINCT DeviceID) AS Devices_Connected
FROM `dataworks-356fa.FirebaseArchive.Firebase_ConnectionInfo`
WHERE PeripheralType = 1 or PeripheralType = 2 or PeripheralType = 12
GROUP BY Serial
ORDER BY Latest_Use DESC
Run Code Online (Sandbox Code Playgroud) 我有一个Python脚本,它从firebase下载数据,操作它然后将其转储到JSON文件中.我可以通过命令行将其上传到BigQuery,但现在我想将一些代码放入Python脚本中以便将其全部完成.
这是我到目前为止的代码.
import json
from firebase import firebase
firebase = firebase.FirebaseApplication('<redacted>')
result = firebase.get('/connection_info', None)
id_keys = map(str, result.keys())
#with open('result.json', 'r') as w:
# connection = json.load(w)
with open("w.json", "w") as outfile:
for id in id_keys:
json.dump(result[id], outfile, indent=None)
outfile.write("\n")
Run Code Online (Sandbox Code Playgroud) 这是我在BigQuery中运行的查询,我想在我的python脚本中运行.我将如何更改此/我必须添加什么才能在Python中运行它.
#standardSQL
SELECT
Serial,
MAX(createdAt) AS Latest_Use,
SUM(ConnectionTime/3600) as Total_Hours,
COUNT(DISTINCT DeviceID) AS Devices_Connected
FROM `dataworks-356fa.FirebaseArchive.testf`
WHERE Model = "BlueBox-pH"
GROUP BY Serial
ORDER BY Serial
LIMIT 1000;
Run Code Online (Sandbox Code Playgroud)
从我一直在研究的是,我不能将这个查询保存为使用Python的永久表.真的吗?如果是真的,是否仍然可以导出临时表?
我正在尝试将 JSON 上传到谷歌云存储。我可以手动完成,所以我知道它可以工作,但现在想编写一个可以自动完成的 python 脚本。
import boto
import gcs_oauth2_boto_plugin
import os
import shutil
import StringIO
import tempfile
import time
from google.cloud import storage
from google.cloud.storage import blob
client = storage.Client(project='dataworks-356fa')
bucket = client.get_bucket('dataworks-356fa-backups')
blob = bucket.blob('t.json')
with open('t.json', 'rb') as f:
blob.upload_from_file('f')
Run Code Online (Sandbox Code Playgroud)
是我到目前为止的代码,这是我得到的错误。
Traceback (most recent call last):
File "uploadcloud.py", line 16, in <module>
blob.upload_from_file('f')
File "/Library/Python/2.7/site-packages/google/cloud/storage/blob.py", line 891, in upload_from_file
client, file_obj, content_type, size, num_retries)
File "/Library/Python/2.7/site-packages/google/cloud/storage/blob.py", line 815, in _do_upload
client, stream, content_type, size, num_retries)
File "/Library/Python/2.7/site-packages/google/cloud/storage/blob.py", line …Run Code Online (Sandbox Code Playgroud) 目前我有一个 Python 脚本向 slack 发送消息。我想添加额外的链接,但不知道如何添加。这是我当前的代码。
def post_slack():
"""Post slack message."""
try:
token = 'xoxp-67503713541-67496795984-216701772021-c23bdfbe9635f1f63a4c802697147dfc'
slack = Slacker(token)
obj = slack.chat.post_message(
channel='#dataworksapp',
as_user= 'false',
username = 'DataWorksBot',
attachments=[
{
"color": "033E96",
"title": "Pressure Transducer Weekly Information",
"title_link": "https://console.cloud.google.com/storage/browser/firebase_results/?project=dataworks-356fa",
"author_name": "Master Table",
"author_link": "https://bigquery.cloud.google.com/table/dataworks-356fa:FirebaseArchive.PT_MasterTable?tab=preview",
"text": "https://bigquery.cloud.google.com/table/dataworks-356fa:FirebaseArchive.PT_MasterTable?tab=preview",
"fields": [
{
"title": "Amount Used:",
"value": "countPTserial1",
"short": 'true'
},{
"title": "Distinct Device ID's:",
"value": "countPTid1",
"short": 'true'
},{
"title": "Total Connection Time (hr):",
"value": "sumPTct2",
"short": 'true'
}
]
Run Code Online (Sandbox Code Playgroud)
我无法找到任何其他类似于“author_link”的字段类别,我可以将其设置为等于链接。我可以设置"text"等于链接,但如果我这样做,我更愿意将链接作为单个单词而不是在消息中发送整个丑陋的链接。
另外,我无法将链接设置为等于变量,然后设置"text" …