2025-10-18 19:21:22 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (C) Artsiom D.
|
|
|
|
|
* Copyright (C) shit-co.de
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2025-10-18 20:44:30 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
|
2025-10-18 19:21:22 +02:00
|
|
|
#include "chart.h"
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
|
|
|
2025-10-18 20:44:30 +02:00
|
|
|
struct chart
|
|
|
|
|
new_chart(unsigned int length)
|
2025-10-18 19:21:22 +02:00
|
|
|
{
|
|
|
|
|
unsigned int i;
|
|
|
|
|
double price;
|
|
|
|
|
struct chart chart;
|
|
|
|
|
|
|
|
|
|
chart.prices = emalloc(sizeof(double) * length);
|
|
|
|
|
chart.length = length;
|
|
|
|
|
|
|
|
|
|
/* populate with random prices */
|
|
|
|
|
|
|
|
|
|
price = 10;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
|
chart.prices[i] = price;
|
2025-10-18 20:44:30 +02:00
|
|
|
price += (double)rand() / RAND_MAX * 4 - 2;
|
2025-10-18 19:21:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return chart;
|
|
|
|
|
}
|
2025-10-18 20:44:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
update_chart(struct chart *chart)
|
|
|
|
|
{
|
|
|
|
|
memmove(chart->prices, chart->prices + 1, (chart->length - 1) * sizeof(double));
|
|
|
|
|
chart->prices[chart->length - 1] = chart->prices[chart->length - 2] + (double)rand() / RAND_MAX * 4 - 2;
|
|
|
|
|
}
|