我开始使用mongodb,我正在尝试查询具有此文档格式的数据库:
{ "_id" : ObjectId("520b8b3f8bd94741bf006033"), "value" : 0.664, "timestamp" : ISODate("2013-08-14T13:48:35Z"), "cr" : ISODate("2013-08-14T13:50:55.834Z") }
Run Code Online (Sandbox Code Playgroud)
我可以使用此查询从日期时间获取最后的记录:
> db.mycol.find({timestamp:{$gt: ISODate("2013-08-14T13:48:00Z")}}).sort({x:1});
Run Code Online (Sandbox Code Playgroud)
但是我试图从18分钟前获得一个带有值字段和时间戳的集合,我该如何为此构建查询?谢谢大家耐心等待...
如何从大日志文件中读取最后两行而不将其完全加载到内存中?
我需要每10秒阅读一次(在Win机器上)...而且我试图读取最后一行...
package main
import (
"fmt"
"time"
"os"
)
const MYFILE = "logfile.log"
func main() {
c := time.Tick(10 * time.Second)
for now := range c {
readFile(MYFILE)
}
}
func readFile(fname string){
file, err:=os.Open(fname)
if err!=nil{
panic(err)
}
buf:=make([]byte, 32)
c, err:=file.ReadAt(32, ????)
fmt.Printf("%s\n", c)
}
Run Code Online (Sandbox Code Playgroud)
日志文件类似于:
07/25/2013 11:55:42.400, 0.559
07/25/2013 11:55:52.200, 0.477
07/25/2013 11:56:02.000, 0.463
07/25/2013 11:56:11.800, 0.454
07/25/2013 11:56:21.600, 0.424
07/25/2013 11:56:31.400, 0.382
07/25/2013 11:56:41.200, 0.353
07/25/2013 11:56:51.000, 0.384
07/25/2013 11:57:00.800, 0.393
07/25/2013 11:57:10.600, 0.456
Run Code Online (Sandbox Code Playgroud)
谢谢!
我在我的表单中有一个多选输入,我试图在我的处理程序中获取所选值,但我不能,我怎么能得到这些值?
<form action="process" method="post">
<select id="new_data" name="new_data class="tag-select chzn-done" multiple="" style="display: none;">
<option value="1">111mm1</option>
<option value="2">222mm2</option>
<option value="3">012nx1</option>
</select>
</form>
Run Code Online (Sandbox Code Playgroud)
我的处理程序:
func myHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.FormValue("new_data")) // result-> []
fmt.Println(r.Form("new_data")) // result-> []
}
Run Code Online (Sandbox Code Playgroud)
表单序列化数据,从JS控制台中选择选项1和2:
>$('#myform').serialize()
>"new_data=1&new_data=2"
Run Code Online (Sandbox Code Playgroud) 我试图在页眉和页脚之间插入一个googlemap地图作为主要内容,但地图得到100%并推倒页脚,我想要在它们之间拟合地图,这样如果我调整窗口大小,所有内容都会自动调整没有出现左栏滚动内容,但我遗漏了一些东西,请有人帮我一把吗?
<html>
<head>
<style type="text/css">
html, body, #map-canvas {
margin: 0;
padding: 0;
height: 100%;
}
#wrapper {
height: auto !important;
min-height: 100%;
height: 100%;
position: relative; /* Required to absolutely position the footer */
}
#footer {
height: 20px; /* Define height of the footer */
position: absolute;
bottom: 0; /* Sit it on the bottom */
left: 0;
width: 100%; /* As wide as it's allowed */
}
#content {
padding-bottom: 20px; /* This should match the height …Run Code Online (Sandbox Code Playgroud) 我想通过值来过滤jquery选项,如果我有:
<select class="generic-widget" id="phone_line" name="phone_line">
<option value=""></option>
<option value="2">71158189</option>
<option value="4">71158222</option>
<option value="3">99199152</option>
<option value="1">98199153</option>
</select>
Run Code Online (Sandbox Code Playgroud)
对于这种情况,我必须显示值为"3"和值="4"的选项.
使用:
$('#phone_line option[value!="3"]').remove();
Run Code Online (Sandbox Code Playgroud)
我只能过滤一个值,但我需要使用x值
我怎样才能做到这一点?谢谢.
我正在尝试解析这个日期时间字符串,但还没有成功,我怎么能得到它?
d = '2014-05-01 18:10:38-04:00'
datetime.datetime.strptime(d,'%Y-%m-%d %H:%M:%S-%Z')
ValueError: time data '2014-05-01 18:10:38-04:00' does not match format '%Y-%m-%d %H:%M:%S%Z'
Run Code Online (Sandbox Code Playgroud) 我想改进这个慢查询,我想添加一个索引,但我不知道哪种索引类型更适合我的情况。
SELECT COUNT(*) ct FROM events
WHERE dtt AT TIME ZONE 'America/Santiago'
>= date(now() AT TIME ZONE 'America/Santiago') + interval '1s'
Run Code Online (Sandbox Code Playgroud)
查询计划:
"Aggregate (cost=128032.03..128032.04 rows=1 width=0) (actual time=3929.083..3929.083 rows=1 loops=1)"
" -> Seq Scan on events (cost=0.00..125937.68 rows=837742 width=0) (actual time=113.080..3926.972 rows=25849 loops=1)"
" Filter: (timezone('America/Santiago'::text, dtt) >= (date(timezone('America/Santiago'::text, now())) + '00:00:01'::interval))"
" Rows Removed by Filter: 2487386"
"Planning time: 0.179 ms"
"Execution time: 3929.136 ms"
Run Code Online (Sandbox Code Playgroud)
注意:根据 Erwin 的建议,查询运行得更快一些,但我认为还不够快。
"Aggregate (cost=119667.76..119667.77 rows=1 width=0) (actual …Run Code Online (Sandbox Code Playgroud) 我有一个包含两个字段的表:
id(serial), data(jsonb)
Run Code Online (Sandbox Code Playgroud)
在数据中,我有一个带有Datetime字段的记录,该记录存储为UNIX时间戳:
{"Device":132,"Datetime": 1434166552,...}
Run Code Online (Sandbox Code Playgroud)
我正在尝试查询范围之间:
SELECT *
FROM trips
WHERE data->>'Datetime' BETWEEN
EXTRACT(EPOCH FROM date '2014-04-01') AND
EXTRACT(EPOCH FROM date '2014-04-15' + interval '1 day')
AND id = 123
Run Code Online (Sandbox Code Playgroud)
信息
ERROR: operator does not exist: text >= double precision
LINE 3: WHERE data->>'Datetime' BETWEEN
Run Code Online (Sandbox Code Playgroud)
我做错了,请云有人帮助我吗?谢谢。
我有这个数据表,我想知道是否有可能创建一个查询,按月计算累积总和,考虑到当月的所有月份.
date_added | qty
------------------------------------
2015-08-04 22:28:24.633784-03 | 1
2015-05-20 20:22:29.458541-03 | 1
2015-04-08 14:16:09.844229-03 | 1
2015-04-07 23:10:42.325081-03 | 1
2015-07-06 18:50:30.164932-03 | 1
2015-08-22 15:01:54.03697-03 | 1
2015-08-06 18:25:07.57763-03 | 1
2015-04-07 23:12:20.850783-03 | 1
2015-07-23 17:45:29.456034-03 | 1
2015-04-28 20:12:48.110922-03 | 1
2015-04-28 13:26:04.770365-03 | 1
2015-05-19 13:30:08.186289-03 | 1
2015-08-06 18:26:46.448608-03 | 1
2015-08-27 16:43:06.561005-03 | 1
2015-08-07 12:15:29.242067-03 | 1
Run Code Online (Sandbox Code Playgroud)
我需要这样的结果:
Jan|0
Feb|0
Mar|0
Apr|5
May|7
Jun|7
Jul|9
Aug|15
Run Code Online (Sandbox Code Playgroud) sql postgresql aggregate-functions window-functions generate-series
我试图运行这个grep复合命令,在cmd上工作正常
grep Rec sy.log | grep e612r2246s768 | grep 2013-07 | grep -oh "'.*'" | wc -c
Run Code Online (Sandbox Code Playgroud)
但这里出了点问题,我还看不到它:
import commands
commands.getstatus("""/bin/grep Rec /var/log/sy.log | /bin/grep e612r2246s768 | /bin/grep 2013-07 | /bin/grep -oh "'.*'" | /usr/bin/wc -c""")
Out[2]: 'ls: cannot access /bin/grep Rec /var/log/sy.log | /bin/grep e612r2246s768 | /bin/grep 2013-07 | /bin/grep -oh "\'.*\'" | /usr/bin/wc -c: No such file or directory'
Run Code Online (Sandbox Code Playgroud)
使用子进程:
import subprocess
cmd = ["""/bin/grep Rec /var/log/sy.log | /bin/grep e612r2246s768 | /bin/grep 2013-07 | /bin/grep -oh "'.*'" | …Run Code Online (Sandbox Code Playgroud) postgresql ×3
go ×2
html ×2
python ×2
python-2.7 ×2
sql ×2
command-line ×1
count ×1
css ×1
forms ×1
google-maps ×1
grep ×1
indexing ×1
jquery ×1
jsonb ×1
mongodb ×1
timezone ×1