Skip to content

Commit

Permalink
Preparing for updated binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
geho2 committed May 22, 2020
1 parent df97c04 commit d3569a8
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 9 deletions.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ mnemonic
coincurve
pycryptodomex
requests_oauth2
rainflow
4 changes: 2 additions & 2 deletions wallet/crystals/400_phonebattery/about.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "GH2",
"description": "Crystal for logging battery data from Android phones",
"email": "N/A",
"version": "1.0.2b",
"date": "2020-05-18",
"version": "1.0.2c",
"date": "2020-05-22",
"url":"https://hypernodes.bismuth.live/?p=1696"
}
178 changes: 178 additions & 0 deletions wallet/crystals/400_phonebattery/rainflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
# coding: utf-8
"""
Implements rainflow cycle counting algorythm for fatigue analysis
according to section 5.4.4 in ASTM E1049-85 (2011).
"""
from __future__ import division
from collections import deque, defaultdict
import math

#try:
# from importlib import metadata as _importlib_metadata
#except ImportError:
# import importlib_metadata as _importlib_metadata
#
#__version__ = _importlib_metadata.version("rainflow")


def _get_round_function(ndigits=None):
if ndigits is None:
def func(x):
return x
else:
def func(x):
return round(x, ndigits)
return func


def reversals(series):
"""Iterate reversal points in the series.
A reversal point is a point in the series at which the first derivative
changes sign. Reversal is undefined at the first (last) point because the
derivative before (after) this point is undefined. The first and the last
points are treated as reversals.
Parameters
----------
series : iterable sequence of numbers
Yields
------
Reversal points as tuples (index, value).
"""
series = iter(series)

x_last, x = next(series), next(series)
d_last = (x - x_last)

yield 0, x_last
for index, x_next in enumerate(series, start=1):
if x_next == x:
continue
d_next = x_next - x
if d_last * d_next < 0:
yield index, x
x_last, x = x, x_next
d_last = d_next
yield index + 1, x_next


def extract_cycles(series):
"""Iterate cycles in the series.
Parameters
----------
series : iterable sequence of numbers
Yields
------
cycle : tuple
Each tuple contains (range, mean, count, start index, end index).
Count equals to 1.0 for full cycles and 0.5 for half cycles.
"""
points = deque()

def format_output(point1, point2, count):
i1, x1 = point1
i2, x2 = point2
rng = abs(x1 - x2)
mean = 0.5 * (x1 + x2)
return rng, mean, count, i1, i2

for point in reversals(series):
i, x = point
points.append(point)

while len(points) >= 3:
# Form ranges X and Y from the three most recent points
x1, x2, x3 = points[-3][1], points[-2][1], points[-1][1]
X = abs(x3 - x2)
Y = abs(x2 - x1)

if X < Y:
# Read the next point
break
elif len(points) == 3:
# Y contains the starting point
# Count Y as one-half cycle and discard the first point
yield format_output(points[0], points[1], 0.5)
points.popleft()
else:
# Count Y as one cycle and discard the peak and the valley of Y
yield format_output(points[-3], points[-2], 1.0)
last = points.pop()
points.pop()
points.pop()
points.append(last)
else:
# Count the remaining ranges as one-half cycles
while len(points) > 1:
yield format_output(points[0], points[1], 0.5)
points.popleft()


def count_cycles(series, ndigits=None, nbins=None, binsize=None):
"""Count cycles in the series.
Parameters
----------
series : iterable sequence of numbers
ndigits : int, optional
Round cycle magnitudes to the given number of digits before counting.
Use a negative value to round to tens, hundreds, etc.
nbins : int, optional
Specifies the number of cycle-counting bins.
binsize : int, optional
Specifies the width of each cycle-counting bin
Arguments ndigits, nbins and binsize are mutually exclusive.
Returns
-------
A sorted list containing pairs of range and cycle count.
The counts may not be whole numbers because the rainflow counting
algorithm may produce half-cycles. If binning is used then ranges
correspond to the right (high) edge of a bin.
"""
if sum(value is not None for value in (ndigits, nbins, binsize)) > 1:
raise ValueError(
"Arguments ndigits, nbins and binsize are mutually exclusive"
)

counts = defaultdict(float)
cycles = (
(rng, count)
for rng, mean, count, i_start, i_end in extract_cycles(series)
)

if binsize is not None:
for rng, count in cycles:
n = math.ceil(rng / binsize)
counts[n * binsize] += count

rng = binsize
while rng < max(counts):
counts.setdefault(rng, 0.0)
rng += binsize

elif nbins is not None:
binsize = (max(series) - min(series)) / nbins
for rng, count in cycles:
n = math.ceil(rng / binsize)
counts[n * binsize] += count

for i in range(nbins):
rng = (i + 1) * binsize
counts.setdefault(rng, 0.0)

elif ndigits is not None:
round_ = _get_round_function(ndigits)
for rng, count in cycles:
counts[round_(rng)] += count

else:
for rng, count in cycles:
counts[rng] += count

return sorted(counts.items())
2 changes: 1 addition & 1 deletion wallet/crystals/400_phonebattery/themes/default/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h4 class="card-title">About</h4>
</div>
<div class="card-body">
Phone Battery Crystal for Bismuth's Tornado Wallet<br/>
Version 1.0.2b<br/>
Version 1.0.2c<br/>
<br/>
GitHub Link: <a href='https://github.com/bismuthfoundation/TornadoWallet/tree/master/wallet/crystals/400_phonebattery'>https://github.com/bismuthfoundation/TornadoWallet/tree/master/wallet/crystals/400_phonebattery</a><br/>
Blog: <a href='https://hypernodes.bismuth.live/?p=1696'>https://hypernodes.bismuth.live/?p=1696</a><br/>
Expand Down
5 changes: 3 additions & 2 deletions wallet/make_dist.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ del /f /s /q build 1>nul
rmdir /s /q build

copy wallet.py TornadoBismuthWallet.py
pyinstaller --hidden-import tornado.locale --hidden-import aiohttp --onefile --icon=favicon.ico TornadoBismuthWallet.py
pyinstaller --hidden-import tornado.locale --hidden-import aiohttp --hidden-import requests_oauth2 --onefile --icon=favicon.ico TornadoBismuthWallet.py
robocopy locale dist/locale /S /E *.mo
mkdir dist/themes
robocopy themes/material dist/themes/material /S /E
robocopy themes/common dist/themes/common /S /E
robocopy crystals dist/crystals /S /E


REM see https://nsis.sourceforge.io/Main_Page , make installer from zip
REM Or inno setup https://cyrille.rossant.net/create-a-standalone-windows-installer-for-your-python-application/
REM or https://pynsist.readthedocs.io/en/latest/index.html
REM or https://pynsist.readthedocs.io/en/latest/index.html
3 changes: 2 additions & 1 deletion wallet/make_dist.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env bash
cp wallet.py TornadoBismuthWallet.py
~/.pyenv/shims/pyinstaller --hidden-import tornado.locale --hidden-import aiohttp --onefile --icon=favicon.ico TornadoBismuthWallet.py
pyinstaller --hidden-import tornado.locale --hidden-import aiohttp --hidden-import requests_oauth2 --onefile --icon=favicon.ico TornadoBismuthWallet.py
cp -r locale dist/locale
mkdir dist/themes
cp -r themes/material dist/themes/material
cp -r themes/common dist/themes/common
cp -r crystals dist/crystals
rm TornadoBismuthWallet.py
3 changes: 2 additions & 1 deletion wallet/make_dist_nuitka.bat
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ ren TornadoBismuthWallet.build build
robocopy locale dist/locale /S /E *.mo
mkdir dist/themes
robocopy themes/material dist/themes/material /S /E
robocopy themes/common dist/themes/common /S /E
robocopy crystals dist/crystals /S /E

REM see https://nsis.sourceforge.io/Main_Page , make installer from zip
REM Or inno setup https://cyrille.rossant.net/create-a-standalone-windows-installer-for-your-python-application/
REM or https://pynsist.readthedocs.io/en/latest/index.html
REM or https://pynsist.readthedocs.io/en/latest/index.html
2 changes: 1 addition & 1 deletion wallet/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from modules.crystals import CrystalManager
from modules import i18n # helps pyinstaller, do not remove

__version__ = "0.1.34"
__version__ = "0.1.35"

define("port", default=8888, help="run on the given port", type=int)
define(
Expand Down

0 comments on commit d3569a8

Please sign in to comment.