<commit_before>#include <iomanip>
#include <iostream>
#include <sstream>

#include <wx/wx.h>
#include <wx/dcclient.h>
#include <wx/dcmemory.h>
#include <wx/file.h>
#include <wx/sizer.h>
#include <wx/sstream.h>
#include <wx/stdpaths.h>
#include <wx/stattext.h>
#include <wx/wfstream.h>
#include <wx/url.h>

#include <greentop/ExchangeApi.h>

#include "dialog/PriceHistory.h"

namespace greenthumb {
namespace dialog {

PriceHistory::PriceHistory(wxWindow *parent, wxWindowID id, const wxString &title,
    const wxPoint &pos, const wxSize &size, long style, const wxString &name) :
    wxDialog(parent, id, title, pos, size, style, name) {

    int borderWidth = 10;
    int borderFlags = wxTOP | wxRIGHT | wxLEFT;

    wxBoxSizer* vbox = new wxBoxSizer(wxVERTICAL);
    lastPriceTraded = new wxStaticText(this, wxID_ANY, "");

    wxFlexGridSizer* gridSizer = new wxFlexGridSizer(2, borderWidth, borderWidth);
    wxStaticText* bettingOnLabel = new wxStaticText(this, wxID_ANY, "Betting on:");
    gridSizer->Add(bettingOnLabel);
    bettingOn = new wxStaticText(this, wxID_ANY, "");
    gridSizer->Add(bettingOn);

    wxStaticText* lastPriceTradedLabel = new wxStaticText(this, wxID_ANY, "Last price matched:");
    gridSizer->Add(lastPriceTradedLabel);
    lastPriceTraded = new wxStaticText(this, wxID_ANY, "");
    gridSizer->Add(lastPriceTraded);
    vbox->Add(gridSizer, 0, borderFlags, borderWidth);

    graphPanel = new ImagePanel(this, wxID_ANY, wxDefaultPosition,
        wxSize(GRAPH_WIDTH, GRAPH_HEIGHT), wxSUNKEN_BORDER);
    vbox->Add(graphPanel, 0, borderFlags, borderWidth);

    wxSizer* buttonSizer = CreateButtonSizer(wxCLOSE);
    if (buttonSizer) {
        vbox->Add(buttonSizer, 0, wxTOP | wxBOTTOM | wxALIGN_RIGHT, borderWidth);
    }

    SetSizer(vbox);
    vbox->Fit(this);

    Bind(wxEVT_BUTTON, &PriceHistory::OnClose, this, wxID_CLOSE);

}

void PriceHistory::SetLastPriceTraded(const double lastPriceTraded) {
    if (lastPriceTraded > 0) {
        std::ostringstream lastPriceStream;
        lastPriceStream << std::fixed << std::setprecision(2) << lastPriceTraded;
        wxString label((lastPriceStream.str()).c_str(), wxConvUTF8);
        this->lastPriceTraded->SetLabel(label);
    }
}

void PriceHistory::SetRunner(const entity::Market& market, const greentop::Runner& runner) {

    if (market.HasRunner(runner.getSelectionId())) {
        greentop::RunnerCatalog rc = market.GetRunner(runner.getSelectionId());
        bettingOn->SetLabel(rc.getRunnerName());
    }

    // bettingOn->SetLabel(runner.GetRunnerName());

    wxBitmap bitmap(GRAPH_WIDTH, GRAPH_HEIGHT);

    wxImage image = bitmap.ConvertToImage();

    wxString filename = GetGraphFilename(market, runner);

    if (image.LoadFile(filename, wxBITMAP_TYPE_JPEG)) {
        graph = wxBitmap(image);
        graphPanel->SetBitmap(graph);
    }

}

/* void PriceHistory::OnPaint(wxPaintEvent &WXUNUSED(event)) {

    if (graph.IsOk()) {
        wxPaintDC dc(graphPanel);
        PrepareDC(dc);
        dc.DrawBitmap(graph, 0, 0);
    }
} */

const wxString PriceHistory::GetGraphFilename(const entity::Market& market, const greentop::Runner& runner) {

    wxStandardPaths sp = wxStandardPaths::Get();
    wxString filename = sp.GetTempDir() + wxT("/graph.jpeg");
    wxString marketId(market.GetMarketCatalogue().getMarketId().substr(2));

    std::ostringstream oStream;
    oStream << runner.getSelectionId();
    wxString selectionId = oStream.str();

    wxString graphHost;
    if (market.GetExchange() == greentop::Exchange::UK) {
        graphHost = wxT("uk.site.sports.betfair.com");
    } else {
        graphHost = wxT("au.site.sports.betfair.com");
    }

    wxURL url(wxT("http://") + graphHost + wxT("/betting/LoadRunnerInfoChartAction.do?marketId=") +
        marketId +
        wxT("&selectionId=") +
        selectionId +
        wxT("&asianLineId=0"));

    if (url.GetError() == wxURL_NOERR) {
<commit_msg>fix price history graph - betfair has changed the url<commit_after>#include <iomanip>
#include <iostream>
#include <sstream>

#include <wx/wx.h>
#include <wx/dcclient.h>
#include <wx/dcmemory.h>
#include <wx/file.h>
#include <wx/sizer.h>
#include <wx/sstream.h>
#include <wx/stdpaths.h>
#include <wx/stattext.h>
#include <wx/wfstream.h>
#include <wx/url.h>

#include <greentop/ExchangeApi.h>

#include "dialog/PriceHistory.h"

namespace greenthumb {
namespace dialog {

PriceHistory::PriceHistory(wxWindow *parent, wxWindowID id, const wxString &title,
    const wxPoint &pos, const wxSize &size, long style, const wxString &name) :
    wxDialog(parent, id, title, pos, size, style, name) {

    int borderWidth = 10;
    int borderFlags = wxTOP | wxRIGHT | wxLEFT;

    wxBoxSizer* vbox = new wxBoxSizer(wxVERTICAL);
    lastPriceTraded = new wxStaticText(this, wxID_ANY, "");

    wxFlexGridSizer* gridSizer = new wxFlexGridSizer(2, borderWidth, borderWidth);
    wxStaticText* bettingOnLabel = new wxStaticText(this, wxID_ANY, "Betting on:");
    gridSizer->Add(bettingOnLabel);
    bettingOn = new wxStaticText(this, wxID_ANY, "");
    gridSizer->Add(bettingOn);

    wxStaticText* lastPriceTradedLabel = new wxStaticText(this, wxID_ANY, "Last price matched:");
    gridSizer->Add(lastPriceTradedLabel);
    lastPriceTraded = new wxStaticText(this, wxID_ANY, "");
    gridSizer->Add(lastPriceTraded);
    vbox->Add(gridSizer, 0, borderFlags, borderWidth);

    graphPanel = new ImagePanel(this, wxID_ANY, wxDefaultPosition,
        wxSize(GRAPH_WIDTH, GRAPH_HEIGHT), wxSUNKEN_BORDER);
    vbox->Add(graphPanel, 0, borderFlags, borderWidth);

    wxSizer* buttonSizer = CreateButtonSizer(wxCLOSE);
    if (buttonSizer) {
        vbox->Add(buttonSizer, 0, wxTOP | wxBOTTOM | wxALIGN_RIGHT, borderWidth);
    }

    SetSizer(vbox);
    vbox->Fit(this);

    Bind(wxEVT_BUTTON, &PriceHistory::OnClose, this, wxID_CLOSE);

}

void PriceHistory::SetLastPriceTraded(const double lastPriceTraded) {
    if (lastPriceTraded > 0) {
        std::ostringstream lastPriceStream;
        lastPriceStream << std::fixed << std::setprecision(2) << lastPriceTraded;
        wxString label((lastPriceStream.str()).c_str(), wxConvUTF8);
        this->lastPriceTraded->SetLabel(label);
    }
}

void PriceHistory::SetRunner(const entity::Market& market, const greentop::Runner& runner) {

    if (market.HasRunner(runner.getSelectionId())) {
        greentop::RunnerCatalog rc = market.GetRunner(runner.getSelectionId());
        bettingOn->SetLabel(rc.getRunnerName());
    }

    // bettingOn->SetLabel(runner.GetRunnerName());

    wxBitmap bitmap(GRAPH_WIDTH, GRAPH_HEIGHT);

    wxImage image = bitmap.ConvertToImage();

    wxString filename = GetGraphFilename(market, runner);

    if (image.LoadFile(filename, wxBITMAP_TYPE_JPEG)) {
        graph = wxBitmap(image);
        graphPanel->SetBitmap(graph);
    }

}

/* void PriceHistory::OnPaint(wxPaintEvent &WXUNUSED(event)) {

    if (graph.IsOk()) {
        wxPaintDC dc(graphPanel);
        PrepareDC(dc);
        dc.DrawBitmap(graph, 0, 0);
    }
} */

const wxString PriceHistory::GetGraphFilename(const entity::Market& market, const greentop::Runner& runner) {

    wxStandardPaths sp = wxStandardPaths::Get();
    wxString filename = sp.GetTempDir() + wxT("/graph.jpeg");
    wxString marketId(market.GetMarketCatalogue().getMarketId().substr(2));

    std::ostringstream oStream;
    oStream << runner.getSelectionId().getValue();
    wxString selectionId = oStream.str();

    wxURL url(wxT("http://sportsiteexweb.betfair.com.au/betting/LoadRunnerInfoChartAction.do?marketId=") +
        marketId +
        wxT("&selectionId=") +
        selectionId);

    if (url.GetError() == wxURL_NOERR) {
{'fraction_non_alphanumeric': 0.1358008601589991, 'fraction_numerical': 0.0032581780268473868, 'mean_word_length': 4.209775967413442, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5188163', 'n_tokens_mistral': 2631, 'n_tokens_neox': 2556, 'n_words': 483}