- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个定义如下的 map :
mapMeasures := make(map[time.Time]models.Measure, 0)
与
type Measure struct {
Delta float64 // I just let one field to simplificate
}
因此初始循环将填充从 22/01/20-10:10:00
到 22/01/20-12:00:00
的值,所以它将存储 12 个键值(10 分钟时间步长)
然后,它将再次循环那些时间戳,并将增量添加到现有值。
因此,我需要检查是否已经存在与我的实际时间戳对应的 key :
if val, ok := mapMeasures[ts]; ok { // ts already exists, we must sum delta values
measure.Delta += val.Delta
}
但似乎这种情况永远不会成立。
我调试了代码,我可以看到时间戳实际上存在于 map 中:
mapMeasures = {map[time.Time]gitlab.com/company/common/models.Measure}
0 = ->
key = {time.Time} 2020-01-22 11:40:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc000132460}
1 = ->
key = {time.Time} 2020-01-22 12:30:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc000132780}
2 = ->
key = {time.Time} 2020-01-22 12:50:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc0001328c0}
3 = ->
key = {time.Time} 2020-01-22 11:00:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc000132140}
4 = ->
key = {time.Time} 2020-01-22 11:10:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc000132280}
5 = ->
key = {time.Time} 2020-01-22 11:20:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc000132320}
6 = ->
key = {time.Time} 2020-01-22 11:30:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc0001323c0}
7 = ->
key = {time.Time} 2020-01-22 11:50:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc000132500}
8 = ->
key = {time.Time} 2020-01-22 12:00:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc0001325a0}
9 = ->
key = {time.Time} 2020-01-22 12:10:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc000132640}
10 = ->
key = {time.Time} 2020-01-22 12:20:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc0001326e0}
11 = ->
key = {time.Time} 2020-01-22 12:40:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc000132820}
实际ts
:
{time.Time} 2020-01-22 11:00:00 +0100
将 key 作为时间戳有什么问题吗?我应该将其转换为字符串还是整数???
最佳答案
引自time.Time
:
Note that the Go == operator compares not just the time instant but also the Location and the monotonic clock reading. Therefore, Time values should not be used as map or database keys without first guaranteeing that the identical Location has been set for all values, which can be achieved through use of the UTC or Local method, and that the monotonic clock reading has been stripped by setting t = t.Round(0). In general, prefer t.Equal(u) to t == u, since t.Equal uses the most accurate comparison available and correctly handles the case when only one of its arguments has a monotonic clock reading.
不要使用 time.Time
作为映射键,而是使用 Time.Unix()
返回的 Unix 时间戳. Unix 时间戳是位置和单调时钟读取“免费”。
如果您的 key 还必须包含位置(时区),则使用包含 Unix 时间戳和时区偏移量的结构,例如:
type Key {
ts int64
offset int
}
参见相关问题:Why do 2 time structs with the same date and time return false when compared with ==?
关于go - 无法使用 if val 从 Golang 中的 map[time.Time]Measure 获取值,ok := mapMeasures[ts]; ok {},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60989254/
我一直在尝试实现塔詹的算法来测量图中的强连通分量。既然我还没有找到任何东西,谁能提供指导,说明如何在阿帕奇时代实现塔詹的算法来测量节点之间的连通性?以下是用python编写的代码。如何使用Apache
我正在尝试更新我的一个 Android 项目的依赖项,但我收到了这个奇怪的错误。 罪魁祸首是这一行,对于 AdMob(我之前使用的是 20.6.0): implementation "com.goog
我在一个目录中有六个 .txt 文件。因此,我创建了一个变量: $foo = gci -Name *.txt $foo 现在是一个包含六个字符串的数组。就我而言,我有 PS > $foo Extens
可能已经在其他一些上下文和依赖项中询问了这个问题。 但即使花了一整天,我仍然无法弄清楚这一点。 所以下面我将完整的错误日志与我的项目级 Gradle 文件和应用级 Gradle 文件一起粘贴。 尝试运
对于我的应用程序,我需要保留用户首选的度量单位。 目前可能的单位是: 升(存储我数据库其余部分的值的单位) 千克(随产品密度变化) 美国液体加仑(3.785411784 升) 美国液体夸脱(以上的 1
我的应用程序遇到性能问题。本质上,我单击一个按钮,列表中填充了数据绑定(bind)数据(由于数据量大,这是虚拟化的),然后单击另一个按钮,该按钮将向关联的 ListView 添加一行。我含糊其词是因为
我需要将一个 Path 对象与另一个进行比较。首先,我在 onTouchEvent 的一个路径中收集所有绘制的对象: switch (event.getAction()) {
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 5 年前。 Improve
swift 4.2 Xcode 10β2 背景 我正在整合一个与天文学相关的 API 来处理我正在开发的应用程序中的数学运算。目的是使用 Measurement 类来处理角度和距离的输入和输出。通过这
前言 View 的工作原理中最重要的就是测量、布局、绘制三大过程,而其中测量是最复杂的; 那么我们就来介绍下View 的测量过程; 1、MeasureSpec 测量自身的大小的时候,会
我知道 getBoundingClientRect() 返回类型为 ClientRect 或 DOMRect 的对象,并且每个对象通常都具有 x、y、width、height 等。如果您 typeof
我有一个脚本来测量执行时间,但是当我使用 Measure-Command 时,我收到了似乎不准确的信息。例如,我自己为脚本计时,大约需要 15 秒才能完成。然而,这里是最后两个输出。如您所见,一个为负
我想从屏幕顶部确定元素的位置。从其他问题来看,一种方法是使用 react native 的 .measure 属性? 引用问题:React Native: Getting the position o
我编写了以下类来通过 GoogleAnalytics 测量我的服务器端流量测量协议(protocol)。 问题是所有活跃的访问者都来自我的服务器当前所在的意大利 - 我假设问题原因来自 fsockop
我想根据规则的数量和规则的复杂性来衡量流口水的表现。因此,我需要测量处理事件所需的时间。我想编写一个像这样的简单测试: long start = System.currentTimeMillis();
考虑以下代码 import numpy as np from skimage import measure def mse(x, y): return np.mean(np.square(x
什么是统一坐标测量? (厘米、米、公里) 如何在其中实现实实在在的措施? 我想在 Unity 中实现一个真正的措施。怎么做? public Vector2 GetAsMeters (Vector2 v
我正在从事一个情感分析项目,而且我是 Python 初学者。我需要计算召回率、精度和 f 度量,但我不知道数据集的语法,如下所示: #The train data format ,contains t
我正在使用 javax.measure 将用户输入转换为秒,秒数可以从秒到天不等,但是从任何单位转换为另一个单位不起作用,这是我设置的。 String units = "d"; double valu
我正在尝试开发 android 应用程序以获取有关网络信息测量的低级信息。 我想知道如何获取这些数据? 3G:-RSCP-ECNO(不是 Eclo)-BER 2G:-RxLevelQuality-Rx
我是一名优秀的程序员,十分优秀!