half-sample 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of half-sample might be problematic. Click here for more details.

@@ -0,0 +1,15 @@
1
+ Metadata-Version: 2.1
2
+ Name: half-sample
3
+ Version: 0.1.0
4
+ Summary: sample data and analysis
5
+ Home-page: https://github.com/KD-Group/Half.Sample
6
+ Author: kunde
7
+ Author-email: gzkunde@163.com
8
+ License: UNKNOWN
9
+ Platform: UNKNOWN
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+
14
+ UNKNOWN
15
+
@@ -0,0 +1,20 @@
1
+ # Half.Sample
2
+
3
+ [![Build status](https://ci.appveyor.com/api/projects/status/04ox7guybqotu67d?svg=true)](https://ci.appveyor.com/project/Wingsgo/half-sample)
4
+
5
+ Sample, C++ Program in Half Application with Python Module
6
+
7
+ ## Requirements
8
+
9
+ Python Requirements:
10
+
11
+ 1. st
12
+ 2. typing
13
+
14
+ Others:
15
+
16
+ 1. C++11 environment
17
+ 2. scons
18
+
19
+ You can also refer to the Travis-CI config file: `.travis.yml`, or Appveyor config file: `appveyor.yml`.
20
+
Binary file
@@ -0,0 +1,15 @@
1
+ Metadata-Version: 2.1
2
+ Name: half-sample
3
+ Version: 0.1.0
4
+ Summary: sample data and analysis
5
+ Home-page: https://github.com/KD-Group/Half.Sample
6
+ Author: kunde
7
+ Author-email: gzkunde@163.com
8
+ License: UNKNOWN
9
+ Platform: UNKNOWN
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+
14
+ UNKNOWN
15
+
@@ -0,0 +1,10 @@
1
+ README.md
2
+ setup.py
3
+ cpp_build/sample.exe
4
+ half_sample.egg-info/PKG-INFO
5
+ half_sample.egg-info/SOURCES.txt
6
+ half_sample.egg-info/dependency_links.txt
7
+ half_sample.egg-info/top_level.txt
8
+ sample/__init__.py
9
+ sample/result.py
10
+ sample/sample.py
@@ -0,0 +1 @@
1
+ sample
@@ -0,0 +1,2 @@
1
+ from .result import Result
2
+ from .sample import Sampler, sampler
@@ -0,0 +1,61 @@
1
+ import math
2
+
3
+
4
+ class Result:
5
+ ErrorMessageMapper = {
6
+ "success": "成功",
7
+ "command_not_found": "命令不存在",
8
+ "sampler_not_found": "采样器不存在",
9
+ "now_in_measuring": "正在测量中",
10
+ "voltage_not_enough": "电压不足",
11
+ "real_sampler_error": "采样器出错",
12
+ "wave_not_found": "未找到波形",
13
+ "appropriate_wave_not_found": "未找到合适波形"
14
+ }
15
+
16
+ def __init__(self):
17
+ self.error = False
18
+ self.message = ''
19
+
20
+ self.sampler_name = ''
21
+ self.measuring = False
22
+ self.success = False
23
+
24
+ self.sampling_interval = 0.0 # us
25
+ self.wave_interval = 0.0 # us
26
+ self.wave = []
27
+ self.time_line = []
28
+ self.estimate = []
29
+
30
+ self.tau = 0.0
31
+ self.w = 0.0
32
+ self.b = 0.0
33
+ self.loss = 0.0
34
+
35
+ self.v0 = 0.0
36
+ self.v_inf = 0.0
37
+
38
+ self.mock_tau = 0.0
39
+ self.mock_v0 = 0.0
40
+ self.mock_v_inf = 0.0
41
+ self.mock_noise = 0.0
42
+
43
+ self.rho = 0.0
44
+ self.miu = 0.0
45
+ self.carrier = 0.0
46
+ self.corrected_rho = 0.0
47
+ self.corrected_miu = 0.0
48
+ self.corrected_carrier = 0.0
49
+
50
+ def process(self):
51
+ self.time_line = [self.wave_interval * i for i in range(len(self.wave))]
52
+
53
+ if self.success:
54
+ tau, w, b = self.tau, self.w, self.b
55
+ self.estimate = [w * math.exp(t / -tau) + b for t in self.time_line]
56
+
57
+ self.v0, self.v_inf = b + w, b
58
+
59
+ @property
60
+ def chinese_message(self) -> str:
61
+ return self.ErrorMessageMapper[self.message]
@@ -0,0 +1,83 @@
1
+ import os
2
+ import shutil
3
+
4
+ import st
5
+ from . import Result
6
+
7
+
8
+ class Sampler:
9
+ @property
10
+ def execution_path(self) -> str:
11
+ main_path = os.path.join(os.path.dirname(__file__), '..')
12
+
13
+ # build if SConstruct file exists
14
+ if os.path.exists(os.path.join(main_path, 'SConstruct')):
15
+ if os.system('cd {} && scons'.format(main_path)) != 0:
16
+ raise self.Error("Compile C++ Driver Error")
17
+
18
+ # try to use cpp_build/sample.exe when developing
19
+ execution_name = 'sample.exe'
20
+ if not os.path.exists(execution_name):
21
+ execution_name = os.path.join(main_path, 'cpp_build', execution_name)
22
+ if os.path.exists(execution_name):
23
+ return os.path.abspath(execution_name)
24
+
25
+ # try to find sample.exe in system path when release
26
+ if shutil.which("sample.exe"):
27
+ return shutil.which("sample.exe")
28
+
29
+ raise self.Error('Sample Driver Not Found')
30
+
31
+ @property
32
+ def p(self) -> st.Process:
33
+ p = getattr(self, 'p_', None)
34
+ if p is not None:
35
+ return p
36
+
37
+ p = st.Process(self.execution_path)
38
+ setattr(self, 'p_', p)
39
+ return p
40
+
41
+ def communicate(self, command: str, executor: st.Process = None) -> Result:
42
+ executor = executor or self.p
43
+
44
+ executor.write_line(command)
45
+ lines = executor.read_until('EOF')
46
+
47
+ result = Result()
48
+ exec(lines, result.__dict__)
49
+
50
+ if result.error:
51
+ raise self.Error("{}: {}".format(result.message, result.chinese_message))
52
+
53
+ return result
54
+
55
+ @property
56
+ def is_measuring(self) -> bool:
57
+ return self.communicate('is_measuring').measuring
58
+
59
+ def measure(self, number_of_waveforms: int, emitting_frequency: float, auto_mode: bool = False) -> None:
60
+ self.communicate("to_measure {} {:.2f} {}".format(number_of_waveforms, emitting_frequency, auto_mode))
61
+
62
+ def set_sampler(self, sampler_name: str) -> Result:
63
+ return self.communicate("set_sampler {}".format(sampler_name))
64
+
65
+ def get_sampler(self) -> Result:
66
+ return self.communicate("get_sampler")
67
+
68
+ def set_sampler_value(self, key: str, value: float) -> Result:
69
+ return self.communicate("set_sampler_value {} {}".format(key, value))
70
+
71
+ def get_sampler_value(self, key: str) -> Result:
72
+ return self.communicate("get_sampler_value {}".format(key))
73
+
74
+ def query(self) -> Result:
75
+ result = self.communicate("to_query")
76
+ result.process()
77
+ return result
78
+
79
+ class Error(RuntimeError):
80
+ pass
81
+
82
+
83
+ sampler = Sampler()
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,18 @@
1
+ import setuptools
2
+
3
+ setuptools.setup(
4
+ name="half-sample",
5
+ version="0.1.0",
6
+ author="kunde",
7
+ author_email="gzkunde@163.com",
8
+ description="sample data and analysis",
9
+ long_description="",
10
+ url="https://github.com/KD-Group/Half.Sample",
11
+ packages=["sample"],
12
+ classifiers=(
13
+ "Programming Language :: Python :: 3",
14
+ "License :: OSI Approved :: MIT License",
15
+ "Operating System :: OS Independent",
16
+ ),
17
+ data_files=[('cpp_build/sample.exe')]
18
+ )