use bin file to save like feature-data.
(self, expression_data, cache_path, instrument, field, freq, last_update)
| 563 | return self.provider.expression(instrument, field, start_time, end_time, freq) |
| 564 | |
| 565 | def gen_expression_cache(self, expression_data, cache_path, instrument, field, freq, last_update): |
| 566 | """use bin file to save like feature-data.""" |
| 567 | # Make sure the cache runs right when the directory is deleted |
| 568 | # while running |
| 569 | meta = { |
| 570 | "info": {"instrument": instrument, "field": field, "freq": freq, "last_update": last_update}, |
| 571 | "meta": {"last_visit": time.time(), "visits": 1}, |
| 572 | } |
| 573 | self.logger.debug(f"generating expression cache: {meta}") |
| 574 | self.clear_cache(cache_path) |
| 575 | meta_path = cache_path.with_suffix(".meta") |
| 576 | |
| 577 | with meta_path.open("wb") as f: |
| 578 | pickle.dump(meta, f, protocol=C.dump_protocol_version) |
| 579 | meta_path.chmod(stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH) |
| 580 | df = expression_data.to_frame() |
| 581 | |
| 582 | r = np.hstack([df.index[0], expression_data]).astype("<f") |
| 583 | r.tofile(str(cache_path)) |
| 584 | |
| 585 | def update(self, sid, cache_uri, freq: str = "day"): |
| 586 | cp_cache_uri = self.get_cache_dir(freq).joinpath(sid).joinpath(cache_uri) |
no test coverage detected