小编Iva*_*van的帖子

Boost,如何解析以下字符串到日期/时间

我有以下毫/秒精度字符串来解析某种提升日期时间.

std::string cell ="20091201 00:00:04.437";
Run Code Online (Sandbox Code Playgroud)

我看过关于方面的文档.像这样的东西

date_input_facet* f = new date_input_facet();
f->format("%Y%m%d %F *");
Run Code Online (Sandbox Code Playgroud)

但我不知道如何使用它们.

我尝试使用从StackOverflow中清除的代码来编写这个程序,但我无法让millis显示:

#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <map>

#include <boost/algorithm/string.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time.hpp>

namespace bt = boost::posix_time;

const std::locale formats[] =
{
    std::locale(std::locale::classic(),new bt::time_input_facet("%Y%m%d %H:%M:%S.f")),
    std::locale(std::locale::classic(),new bt::time_input_facet("%Y-%m-%d %H:%M:%S")),
    std::locale(std::locale::classic(),new bt::time_input_facet("%Y/%m/%d %H:%M:%S")),
    std::locale(std::locale::classic(),new bt::time_input_facet("%d.%m.%Y %H:%M:%S")),
    std::locale(std::locale::classic(),new bt::time_input_facet("%Y-%m-%d"))
};

const size_t formats_n = sizeof(formats) / sizeof(formats[0]);

std::time_t pt_to_time_t(const bt::ptime& pt)
{
    bt::ptime timet_start(boost::gregorian::date(1970,1,1));
    bt::time_duration diff = pt - timet_start;

    return diff.ticks()/bt::time_duration::rep_type::ticks_per_second;

}

void …
Run Code Online (Sandbox Code Playgroud)

c++ boost-date-time

4
推荐指数
1
解决办法
3854
查看次数

将scrapy转换为lxml

我有看起来像这样的scrapy代码

for row in response.css("div#flexBox_flex_calendar_mainCal table tr.calendar_row"):
    print "================" 
        print row.xpath(".//td[@class='time']/text()").extract()
        print row.xpath(".//td[@class='currency']/text()").extract()
        print row.xpath(".//td[@class='impact']/span/@title").extract()
        print row.xpath(".//td[@class='event']/span/text()").extract()
        print row.xpath(".//td[@class='actual']/text()").extract()
        print row.xpath(".//td[@class='forecast']/text()").extract()
        print row.xpath(".//td[@class='previous']/text()").extract()
    print "================" 
Run Code Online (Sandbox Code Playgroud)

我可以像这样使用纯 python 获得相同的东西,

from lxml import html
import requests

page = requests.get('http://www.forexfactory.com/calendar.php?day=dec1.2011')

tree = html.fromstring(page.text)

print tree.xpath(".//td[@class='time']/text()")
print tree.xpath(".//td[@class='currency']/text()")
print tree.xpath(".//td[@class='impact']/span/@title")
print tree.xpath(".//td[@class='event']/span/text()")
print tree.xpath(".//td[@class='actual']/text()")
print tree.xpath(".//td[@class='forecast']/text()")
print tree.xpath(".//td[@class='previous']/text()")
Run Code Online (Sandbox Code Playgroud)

但是我需要逐行执行此操作。我第一次尝试移植到 lxml 不起作用:

from lxml import html
import requests

page = requests.get('http://www.forexfactory.com/calendar.php?day=dec1.2011')

tree = html.fromstring(page.text)

for row in tree.css("div#flexBox_flex_calendar_mainCal table tr.calendar_row"):
    print row.xpath(".//td[@class='time']/text()")
    print row.xpath(".//td[@class='currency']/text()")
    print …
Run Code Online (Sandbox Code Playgroud)

python lxml scrapy

4
推荐指数
1
解决办法
1265
查看次数

如何在 jupyter 中打印希腊字母

如果我说

plt.title(r'$\tau$')
Run Code Online (Sandbox Code Playgroud)

或者

plt.xlabel(r'$\tau$')
Run Code Online (Sandbox Code Playgroud)

jupyter笔记本中,我得到希腊字母 tau。

我如何对文本执行同样的操作?

这不起作用:

print(r'$\tau$', tau)
Run Code Online (Sandbox Code Playgroud)

jupyter-notebook

4
推荐指数
1
解决办法
2万
查看次数

将BeginInvoke转换为async/await

我有一个apiClient.OrderSend必须在"GUI"线程内调用的函数,所以我创建了这个函数

   private void RunOnUIThread(Action action)
   {
        this.BeginInvoke(action);
   }
Run Code Online (Sandbox Code Playgroud)

然后,我有一个需要的功能returnint这样的

    int AlgoSendOrder(MT4Order order)
    {
        int retVal = -1;

        RunOnUIThread(() =>
        {
            retVal = apiClient.OrderSend(order.Symbol, (TradeOperation)order.OrderSide, order.Volume,
                                        order.Price, order.AllowedSlippage ?? default(int),
                                        order.PriceToStopLoss ?? default(double),
                                        order.PriceToTakeProfit ?? default(double));
        });

        return retVal;
    }
Run Code Online (Sandbox Code Playgroud)

问题是AlgoSendOrder返回之前apiClient.OrderSend返回,因此retVal对于此函数的客户端始终为-1.

看来这个合理的改变就是await-async在GUI线程中使用pair执行函数,并具有等待返回值的预期效果.但是我似乎无法让它发挥作用.

好像我应该可以返工RunOnUIThread使用async-await

public async Task RunOnUIThreadAsync()
{
    if (InvokeRequired)
    {
        // what do I put here?
    }
    {
        … // like before (but …
Run Code Online (Sandbox Code Playgroud)

c# begininvoke winforms async-await

3
推荐指数
1
解决办法
2913
查看次数

对象无效作为React子对象(找到:具有键{}的对象)

我通过socket.io一个对象发送到这样的react应用程序:

function getApiAndEmit(socket, quote) 
{
    try 
    {
        var { ticker, type, price, size, timestamp } = quote;
        socket.emit("FromAPI", quote);
        //console.log(ticker, type, price, size, timestamp)
    } 
    catch (error) 
    {
        console.error(`Error: ${error.code}`);
    }
};
Run Code Online (Sandbox Code Playgroud)

当我尝试在客户端呈现它时,我收到错误:

If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons.
Run Code Online (Sandbox Code Playgroud)

使用Web浏览器呈现字段的正确方法是什么react

代码

import React, { Component } from "react";
import socketIOClient from "socket.io-client";

class App extends Component { …
Run Code Online (Sandbox Code Playgroud)

reactjs

3
推荐指数
1
解决办法
1万
查看次数

创建非聚集索引超时

在usingnon-clustered index上创建时,我收到此消息。我尝试更改设置,但没有帮助:tableSSMStimeoutdatabase

USE Options ;  
GO  
EXEC sp_configure 'remote query timeout', 0 ;  
GO  
RECONFIGURE ;  
GO  
Run Code Online (Sandbox Code Playgroud)

sql服务器错误:

===================================

Create failed for Index 'NonClusteredIndex-20200121-151256'.  (Microsoft.SqlServer.Smo)

------------------------------
For help, click: https://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=15.0.18142.0+((SSMS_Rel).190722-0816)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Create+Index&LinkId=20476

------------------------------
Program Location:

   at Microsoft.SqlServer.Management.Smo.SqlSmoObject.CreateImpl()
   at Microsoft.SqlServer.Management.Smo.Index.Create()
   at Microsoft.SqlServer.Management.Smo.IndexExtender.IndexExtenderHelper.Execute(IndexAction action)
   at Microsoft.SqlServer.Management.RelationalEngineTasks.IndexTaskFormComponent.PerformTask(ITaskExecutionContext context)
   at Microsoft.SqlServer.Management.RelationalEngineTasks.IndexTaskFormComponent.Microsoft.SqlServer.Management.ITask.Perform(ITaskExecutionContext )
   at Microsoft.SqlServer.Management.TaskForms.TaskExecutionManager.ExecuteTaskSequence(ISfcScriptCollector collector)

===================================

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

------------------------------
Program Location:

   at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType, Boolean retry)
   at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(StringCollection sqlCommands, …
Run Code Online (Sandbox Code Playgroud)

sql-server ssms

3
推荐指数
1
解决办法
2924
查看次数

Boost::Asio 组播监听地址

我有一个这样的听众:

 receiver r(io_service,
               boost::asio::ip::address::from_string(argv[1]),
               boost::asio::ip::address::from_string(argv[2]));
Run Code Online (Sandbox Code Playgroud)

如果我使用参数运行代码

./BoostAsioMCReceiver 0.0.0.0 239.255.0.1
Run Code Online (Sandbox Code Playgroud)

侦听器从发送者(在另一台计算机上)获取所有多播数据包。但是,如果我实际上输入机器的以太网IP地址,例如

./BoostAsioMCReceiver 172.22.1.5 239.255.0.1
Run Code Online (Sandbox Code Playgroud)

接收方似乎没有收到任何数据包。我需要这样做是因为计算机有多个以太网卡,并且我需要确保数据包从给定的 NIC 发出,并通过扩展到达正确的交换机。

接收器看起来像这样:

receiver(boost::asio::io_service& io_service,
         const boost::asio::ip::address& listen_address,
         const boost::asio::ip::address& multicast_address)
    : socket_(io_service)
{
    boost::asio::ip::udp::endpoint listen_endpoint(
        listen_address, multicast_port);
    socket_.open(listen_endpoint.protocol());
    socket_.set_option(boost::asio::ip::udp::socket::reuse_address(true));
    socket_.bind(listen_endpoint);

    socket_.set_option(
        boost::asio::ip::multicast::join_group(multicast_address));

    socket_.async_receive_from(
        boost::asio::buffer(data, max_length), sender_endpoint,
        boost::bind(&receiver::handle_receive_from, this,
                    boost::asio::placeholders::error,
                    boost::asio::placeholders::bytes_transferred));
}

private:
boost::asio::ip::udp::socket socket;
boost::asio::ip::udp::endpoint sender_endpoint;
Run Code Online (Sandbox Code Playgroud)

为什么会发生这种情况?建议的修复方法是什么?

谢谢。

c++ boost boost-asio

2
推荐指数
1
解决办法
8594
查看次数

从C#到F#的回调

我有一个F#类库:

namespace FsharpTestSystem

open System
open System.IO

open TCLoggerEntity
open TCIQuoteEntity

type TestCallback() = 
    member this.LoggerOutput() = Logger.Info("F#")
    member this.OnQuote(q : TCQuote) = Console.WriteLine(q.ToString())
Run Code Online (Sandbox Code Playgroud)

将这个F#程序集的引用添加到C#项目中,我测试过我可以从C#中调用LoggerOutput.但是,如果我尝试在F#中执行C#事件回调,则会在下面的行中出现错误:

来自C#:

using FsharpTestSystem;

public delegate void QuoteChangeEvent(TCQuote q);
event QuoteChangeEvent OnQuoteChange;

TestCallback fsts = new TestCallback();
api.MAPI.OnQuoteChange += fsts.OnQuote(); // this doesn't work

fsts.LoggerOutput(); // This works fine
Run Code Online (Sandbox Code Playgroud)

c# f#

2
推荐指数
1
解决办法
88
查看次数

如何将匿名类型传递给函数,然后获取值

我有一个function这样的:

private void DropIncompleteQuarters(//what goes in here? This? IEnumerable<dynamic> gb)
{
    foreach(var groupInGb in gb)
    {
        // What goes in here to get each element?
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在生成Grouping这样的:

histData = new List<OHLC>();

var gb = histData.GroupBy(o => new
{
    Year = o.Date.Year,
    Quarter = ((o.Date.Month - 1) / 3) + 1
})
.ToDictionary(g => g.Key, g => g.ToList());
Run Code Online (Sandbox Code Playgroud)

我想传递gbDropIncompleteQuarters,但我不确定type应该是什么。

然后在里面DropIncompleteQuarters,我想迭代一下items

c# grouping dynamic anonymous-types

2
推荐指数
1
解决办法
57
查看次数

建模域类型

限价具有小数值.市场价格没有.

如何在F#中对此进行建模?

module TradingDomain

let NoPrice = None

type PriceActionType = 
    | Limit of decimal
    | Market of NoPrice
Run Code Online (Sandbox Code Playgroud)

f#

1
推荐指数
1
解决办法
61
查看次数