99import csv
1010import re
1111import logging
12- from typing import Final , Optional , List , Dict , Callable , Any , Generator , TYPE_CHECKING
12+ from typing import Final , Optional , List , Dict , Callable , Any , Generator
1313
1414
15- if TYPE_CHECKING :
16- from artisanlib .main import ApplicationWindow # noqa: F401 # pylint: disable=unused-import
17-
1815try :
1916 from PyQt6 .QtCore import QDateTime , Qt , QMutex , QWaitCondition , QUrl # @UnusedImport @Reimport @UnresolvedImport
2017except ImportError :
2118 from PyQt5 .QtCore import QDateTime , Qt , QMutex , QWaitCondition , QUrl # type: ignore # @UnusedImport @Reimport @UnresolvedImport
2219
23- from artisanlib .util import encodeLocal
20+ from artisanlib .util import encodeLocal , encodeLocalStrict
2421from artisanlib .atypes import ProfileData
2522
2623
3128_log : Final [logging .Logger ] = logging .getLogger (__name__ )
3229
3330
34- def url_to_profile (url :str , log_data : bool = False ) -> IkawaCmd_pb2 .RoastProfile : # pylint: disable=no-member
31+ def url_to_profile (url :str ) -> IkawaCmd_pb2 .RoastProfile : # pylint: disable=no-member
3532 url += '=='
3633 base64_bytes = url .encode ('ascii' )
3734 message_bytes = base64 .b64decode (base64_bytes )
38- if log_data :
39- _log .info ('ikawa profile: %s' ,message_bytes )
35+ # _log.debug('ikawa profile: %s',message_bytes)
4036 return IkawaCmd_pb2 .RoastProfile ().FromString (message_bytes ) # pylint: disable=no-member
4137
42- def extractProfileIkawaURL (url :QUrl , aw :'ApplicationWindow' ) -> ProfileData :
43- ikawa_profile = url_to_profile (url .query (), log_data = aw .qmc .device_logging )
38+ def extractProfileIkawaURL (url :QUrl ,
39+ etypesdefault :List [str ],
40+ _alt_etypesdefault :List [str ],
41+ _artisanflavordefaultlabels :List [str ],
42+ eventsExternal2InternalValue :Callable [[int ],float ]) -> ProfileData :
43+ ikawa_profile = url_to_profile (url .query ())
4444 res :ProfileData = ProfileData () # the interpreted data set
4545 res ['samplinginterval' ] = 1.0
4646
@@ -79,8 +79,7 @@ def extractProfileIkawaURL(url:QUrl, aw:'ApplicationWindow') -> ProfileData:
7979 extra4 .append (fan )
8080 extra5 .append (- 1.0 )
8181 extra6 .append (- 1.0 )
82- v = fan / 10. + 1
83- specialeventsvalue .append (v )
82+ specialeventsvalue .append (eventsExternal2InternalValue (int (round (fan ))))
8483 specialevents .append (idx )
8584 specialeventstype .append (0 )
8685 specialeventsStrings .append (f'{ int (fan )} ' + '%' )
@@ -98,8 +97,7 @@ def extractProfileIkawaURL(url:QUrl, aw:'ApplicationWindow') -> ProfileData:
9897 # we add the fan information
9998 fan = round (fan_points [0 ].power / 2.55 )
10099 extra4 .append (fan )
101- v = fan / 10. + 1
102- specialeventsvalue .append (v )
100+ specialeventsvalue .append (eventsExternal2InternalValue (fan ))
103101 specialevents .append (idx )
104102 specialeventstype .append (0 )
105103 specialeventsStrings .append (f'{ int (fan )} ' + '%' )
@@ -111,8 +109,7 @@ def extractProfileIkawaURL(url:QUrl, aw:'ApplicationWindow') -> ProfileData:
111109 extra6 .append (- 1.0 )
112110
113111 cooldown_fan = round (ikawa_profile .cooldown_fan .power / 2.55 )
114- v = cooldown_fan / 10. + 1
115- specialeventsvalue .append (v )
112+ specialeventsvalue .append (eventsExternal2InternalValue (cooldown_fan ))
116113 specialevents .append (len (timex )- 1 )
117114 specialeventstype .append (0 )
118115 specialeventsStrings .append (f'{ int (cooldown_fan )} ' + '%' )
@@ -150,12 +147,16 @@ def extractProfileIkawaURL(url:QUrl, aw:'ApplicationWindow') -> ProfileData:
150147 res ['specialeventsvalue' ] = specialeventsvalue
151148 res ['specialeventsStrings' ] = specialeventsStrings
152149
153- res ['etypes' ] = aw . qmc . etypesdefault
150+ res ['etypes' ] = etypesdefault
154151 return res
155152
156153
157154# returns a dict containing all profile information contained in the given IKAWA CSV file
158- def extractProfileIkawaCSV (file :str , aw :'ApplicationWindow' ) -> ProfileData :
155+ def extractProfileIkawaCSV (file :str ,
156+ etypesdefault :List [str ],
157+ _alt_etypesdefault :List [str ],
158+ _artisanflavordefaultlabels :List [str ],
159+ eventsExternal2InternalValue :Callable [[int ],float ]) -> ProfileData :
159160 res :ProfileData = ProfileData () # the interpreted data set
160161
161162 res ['samplinginterval' ] = 1.0
@@ -190,8 +191,6 @@ def extractProfileIkawaCSV(file:str, aw:'ApplicationWindow') -> ProfileData:
190191 fan_last :Optional [float ] = None # holds the fan event value before the last one
191192 heater :Optional [float ] = None # holds last processed heater event value
192193 heater_last :Optional [float ] = None # holds the heater event value before the last one
193- # fan_event:bool = False # set to True if a fan event exists
194- # heater_event:bool = False # set to True if a heater event exists
195194 specialevents :List [int ] = []
196195 specialeventstype :List [int ] = []
197196 specialeventsvalue :List [float ] = []
@@ -282,9 +281,7 @@ def extractProfileIkawaCSV(file:str, aw:'ApplicationWindow') -> ProfileData:
282281 else :
283282 fan_last = fan
284283 fan = v
285- # fan_event = True
286- v = v / 10. + 1
287- specialeventsvalue .append (v )
284+ specialeventsvalue .append (eventsExternal2InternalValue (int (round (v ))))
288285 specialevents .append (i - 1 )
289286 specialeventstype .append (0 )
290287 specialeventsStrings .append (f'{ fan } ' + '%' )
@@ -313,9 +310,7 @@ def extractProfileIkawaCSV(file:str, aw:'ApplicationWindow') -> ProfileData:
313310 else :
314311 heater_last = heater
315312 heater = v
316- # heater_event = True
317- v = v / 10. + 1
318- specialeventsvalue .append (v )
313+ specialeventsvalue .append (eventsExternal2InternalValue (int (round (v ))))
319314 specialevents .append (i - 1 )
320315 specialeventstype .append (3 )
321316 specialeventsStrings .append (f'{ heater } ' + '%' )
@@ -357,8 +352,8 @@ def extractProfileIkawaCSV(file:str, aw:'ApplicationWindow') -> ProfileData:
357352 res ['specialeventsvalue' ] = specialeventsvalue
358353 res ['specialeventsStrings' ] = specialeventsStrings
359354
360- res ['etypes' ] = aw . qmc . etypesdefault
361- res ['title' ] = Path (file ).stem
355+ res ['etypes' ] = etypesdefault
356+ res ['title' ] = encodeLocalStrict ( Path (file ).stem )
362357 return res
363358
364359
0 commit comments