diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml new file mode 100644 index 0000000..1cce8d3 --- /dev/null +++ b/.github/workflows/linux.yml @@ -0,0 +1,46 @@ +name: ci-debian + +on: + push: + paths-ignore: + - '**.md' + pull_request: + paths-ignore: + - '**.md' + +# The below variables reduce repetitions across similar targets +env: + APT_SET_CONF: | + echo "Acquire::Retries \"3\";" | sudo tee -a /etc/apt/apt.conf.d/80-custom + echo "Acquire::http::Timeout \"120\";" | sudo tee -a /etc/apt/apt.conf.d/80-custom + echo "Acquire::ftp::Timeout \"120\";" | sudo tee -a /etc/apt/apt.conf.d/80-custom + +jobs: + build-ubuntu: + runs-on: ubuntu-latest + env: + CCACHE_TEMPDIR: /tmp/.ccache-temp + strategy: + fail-fast: false + steps: + - uses: actions/checkout@v1 + with: + submodules: recursive + - name: prepare environment + run: util/prep-env.sh + - name: set apt conf + run: ${{env.APT_SET_CONF}} + - name: install dependencies + run: util/deps-pull.sh + - name: build & install the unmanaged dependencies + run: util/deps-build.sh + - name: build + run: ./ci-default + - name: run demo + run: ./ci-default +# It doesn't make sense for now, since we're not linking Boost statically yet. + - uses: actions/upload-artifact@v3 + with: + name: SolOptXMR-ubuntu-latest + path: /home/runner/work/SolOptXMR/SolOptXMR/build/*.png + diff --git a/.gitignore b/.gitignore index d83cbbc..afd6daa 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,6 @@ # Python *.pyc .venv/ + +# Build dirs +build/ diff --git a/ci-default b/ci-default new file mode 120000 index 0000000..b2d424e --- /dev/null +++ b/ci-default @@ -0,0 +1 @@ +util/ci-debian.sh \ No newline at end of file diff --git a/src/generator.py b/src/generator.py index 5c1e1b8..c205a7f 100755 --- a/src/generator.py +++ b/src/generator.py @@ -28,6 +28,7 @@ config = config_builder.parse_config('config.json') ELEVATION_KEY = config.generator.ELEVATION_KEY +BUILD_DIR='build/' # TODO: Config # Not changable: system params MIN_POWER = config.generator.MIN_POWER @@ -77,6 +78,10 @@ def plot_sun(name, elev, bat, usage): plt.plot(list_to_pd([MAX_USAGE] * len(elev), elev)) plt.grid() plt.legend(['sun input', 'bat capacity', 'power usage', 'max cap', 'half cap', 'max usage']) + os.makedirs(BUILD_DIR, exist_ok=True) + fout_rel_path = "{}/fig-{}.png".format(BUILD_DIR, name) + print("Saving figure to:",fout_rel_path) + plt.savefig(fout_rel_path) plt.show() def proc_data(pos): @@ -213,7 +218,7 @@ def get_usage_endor_example(available): hashrates.append(hashrate) usage.append(use) - return "Endor's", hashrates, usage, loads, bat_sim, incomes, costs, effs + return "Endor", hashrates, usage, loads, bat_sim, incomes, costs, effs def get_usage_simple(available): usage_exp = [MAX_USAGE] * len(available) @@ -255,17 +260,17 @@ def print_profits(incomes, costs): print(f"Total cost = {cost:.2f} USD") print(f"Total profit = {profit:.2f} USD") print(f"Profitability = {profitability:.2f} %") - -def get_usage(available): - name, hashrates, usage, bat, bat_sim, incomes, costs, effs = get_usage_simple(available) - #name, hashrates, usage, bat, bat_sim, incomes, costs, effs = get_usage_endor_example(available) - print("Algo name: ", name) + +def get_usage(available, algo): + name, hashrates, usage, bat, bat_sim, incomes, costs, effs = algo(available) + print("\nAlgo name: ", name) bat_sim.print_stats(len(available)) print_hashes(hashrates) print_profits(incomes, costs) - # print(effs) # Check if efficiency is reasonable + #print(effs) # Check if efficiency is reasonable # return name, list_to_pd(usage, available), list_to_pd(incomes, available), list_to_pd(costs, available), list_to_pd(bat, available) - return name, list_to_pd(usage, available), list_to_pd(bat, available) + return name, list_to_pd(usage, available), list_to_pd(bat, available) + def list_to_pd(listt, df): return pd.DataFrame(listt, index=df.index.copy()) @@ -277,11 +282,18 @@ def simul_weather(pos): return pos +def run_main(elev): + run_algo(elev, get_usage_simple) + run_algo(elev, get_usage_endor_example) + +def run_algo(elev, algo): + name, usage, bat = get_usage(elev, algo) + plot_sun(name, elev, bat, usage) + pos = get_sun_positions() #print(pos) proc = proc_data(pos) elev = extr_data(proc) -name, usage, bat = get_usage(elev) -# name, usage, incomes, costs, bat = get_usage(elev) -plot_sun(name, elev, bat, usage) +run_main(elev) + diff --git a/util/ci-debian.sh b/util/ci-debian.sh new file mode 100755 index 0000000..8586d89 --- /dev/null +++ b/util/ci-debian.sh @@ -0,0 +1,4 @@ +#!/bin/sh -e + +python3 src/generator.py + diff --git a/util/deps-build.sh b/util/deps-build.sh new file mode 100755 index 0000000..f6eb068 --- /dev/null +++ b/util/deps-build.sh @@ -0,0 +1,2 @@ +#!/bin/sh -e + diff --git a/util/deps-pull.sh b/util/deps-pull.sh new file mode 100755 index 0000000..0aa1b42 --- /dev/null +++ b/util/deps-pull.sh @@ -0,0 +1,5 @@ +#!/bin/sh -e + +#sudo apt install gfortran libffi-dev +#sudo apt install libffi-dev +pip3 install -r requirements.txt diff --git a/util/prep-env.sh b/util/prep-env.sh new file mode 100755 index 0000000..f6eb068 --- /dev/null +++ b/util/prep-env.sh @@ -0,0 +1,2 @@ +#!/bin/sh -e +