| from datasets import DatasetBuilder, DownloadManager, DatasetInfo, BuilderConfig, SplitGenerator, Split, Features, Value
|
| import pandas as pd
|
|
|
|
|
| class CryptoDataConfig(BuilderConfig):
|
| def __init__(self, features, **kwargs):
|
| super().__init__(**kwargs)
|
| self.features = features
|
|
|
| class CryptoDataDataset(DatasetBuilder):
|
|
|
| BUILDER_CONFIGS = [
|
| CryptoDataConfig(
|
| name="candles",
|
| description="This configuration includes open, high, low, close, and volume.",
|
| features=Features({
|
| "date": Value("string"),
|
| "open": Value("float"),
|
| "high": Value("float"),
|
| "low": Value("float"),
|
| "close": Value("float"),
|
| "volume": Value("float")
|
| })
|
| ),
|
| CryptoDataConfig(
|
| name="indicators",
|
| description="This configuration extends basic CryptoDatas with RSI, SMA, and EMA indicators.",
|
| features=Features({
|
| "date": Value("string"),
|
| "open": Value("float"),
|
| "high": Value("float"),
|
| "low": Value("float"),
|
| "close": Value("float"),
|
| "volume": Value("float"),
|
| "rsi": Value("float"),
|
| "sma": Value("float"),
|
| "ema": Value("float")
|
| })
|
| ),
|
| ]
|
|
|
| def _info(self):
|
| return DatasetInfo(
|
| description=f"CryptoData dataset for {self.config.name}",
|
| features=self.config.features,
|
| supervised_keys=None,
|
| homepage="https://hub.huggingface.co/datasets/sebdg/crypto_data",
|
| citation="No citation for this dataset."
|
| )
|
|
|
| def _split_generators(self, dl_manager: DownloadManager):
|
|
|
|
|
|
|
| return [
|
| SplitGenerator(
|
| name=Split.TRAIN,
|
| gen_kwargs={"filepath": "indicators.csv"},
|
| ),
|
| ]
|
|
|
| def _generate_examples(self, filepath):
|
|
|
| with open(filepath, encoding="utf-8") as csv_file:
|
| data = pd.read_csv(csv_file)
|
| for id, row in data.iterrows():
|
|
|
| features = {feature: row[feature] for feature in self.config.features if feature in row}
|
| yield id, features
|
|
|