def bar(fd): from mlib.wolf.wolf_figs import defaultPlotOptions x = fd.x y = fd.y maxY = wl.All if fd.maxY is None or fd.maxY == -np.inf else fd.maxY minY = wl.All if fd.minY is None or fd.maxY == np.inf else fd.minY maxX = wl.All if fd.maxX is None or fd.maxY == -np.inf else fd.maxX minX = wl.All if fd.minX is None or fd.maxY == np.inf else fd.minX if maxY != wl.All and minY != wl.All: diff = maxY - minY pad = diff * 100 / fd.y_pad_percent maxY = maxY + pad minY = minY - pad rotate = wlexpr('90 Degree') if fd.bar_sideways_labels else wlexpr( '0 Degree') err = fd.err rotate = '90 Degree' if fd.bar_sideways_labels else '0 Degree' vstring = '\n\n\n' if fd.bar_sideways_labels else '' labs = [wl.Text(xx) for xx in x] map_expr = wlexpr('Around[#1, #2] &') labs = str(fd.x).replace('[', '{').replace(']', '}').replace("'", '"') firstarg = wl.MapThread(map_expr, [y, err]) origarg = firstarg if fd.delta_bar_idx is not None: # thing[] firstarg = weval(firstarg) firstarg = list(firstarg) firstarg[fd.delta_bar_idx] = wl.Callout( firstarg[fd.delta_bar_idx], "p=" + str(fd.delta_val), wl.Above, wl.Rule(wl.LabelStyle, [10, wl.Bold, wl.White]), wl.Rule(wl.LeaderSize, 25)) return weval( wl.BarChart( firstarg, defaultPlotOptions(fd), wl.Rule(wl.ChartStyle, [wl.RGBColor(color) for color in fd.item_colors]), wl.Rule( wl.LabelingFunction, wlexpr('(Placed[Rotate[' + labs + '[[#2[[2]]]], ' + rotate + '], Below]&)')), wl.Rule(wl.FrameTicks, [[True, wlexpr('None')], [wlexpr('None'), wlexpr('None')]]), wl.Rule(wl.FrameLabel, [vstring + fd.x_label, fd.y_label])))
def manage(): cloud_files = weval(wl.CloudObjects(wlexpr('$CloudRootDirectory'))) for wcf in listmap(File, cloud_files): if wcf.abspath in _REGISTERED_SUBROOTS: pass elif wcf.abspath == _MAIN_SUBROOT: @log_invokation(with_args=True, stack=True) def recurse_cloud_file(sub_wcf): # f = File(f'{sub_wcf.abspath}') if not sub_wcf.exists: recurse_cloud_file.my_stacker.done = True if boolinput( f'{sub_wcf} is not mirrored locally, delete cloud file?' ): sub_wcf.wc.delete() if sub_wcf.wc.isdir: if Folder(sub_wcf)['.CLOUD_FILES.txt'].exists: Folder(sub_wcf)['.CLOUD_FILES.txt'].write('\n'.join( listmap( lambda e: e.abspath.replace( f'{Folder(sub_wcf).abspath}/', ''), sub_wcf.wc.files))) else: [recurse_cloud_file(c) for c in sub_wcf.wc.files] recurse_cloud_file(wcf) recurse_cloud_file.my_stacker.done = True else: err(f'{wcf.abspath} is not a registered Wolfram Cloud subroot')
def image(cls, fd): log('making image') im = wl.Image(str(fd.x).replace('[', '{').replace(']', '}')) # "Byte" im = str(im).replace("'", "") from mlib.wolf.wolfpy import weval im = weval(im) log('made image') return im
def __init__(self, abs, remote=None, mker=False, w=None, default=None, quiet=None): # print('making file') # log('f1') self.allow_autoload = False self.IGNORE_DS_STORE = False self.DELETE_DS_STORE = True self._default = default self.stop_np_iter = False if isstr(abs) and not os.path.isabs(abs): self.isSSH = 'test-3' in abs # abs = os.path.join(mypwd(), abs) abs = os.path.abspath(abs) elif isstr(abs): self.isSSH = 'test-3' in abs elif isinstsafe(abs, File): self.isSSH = abs.isSSH abs = abs.abspath elif abs.__class__.__name__ == 'WLFunction': from wolframclient.language import wl # 1 sec import from mlib.wolf.wolfpy import weval # 1 sec import if str(weval(wl.Head(abs))) == 'CloudObject': self.isSSH = False url = abs[0] if BASE_WOLFRAM_URL not in url: err(f'{BASE_WOLFRAM_URL=} not in {url=}') else: abs = url.replace(BASE_WOLFRAM_URL, '') else: err(f'only use cloud objects, not {weval(wl.Head(abs))=}') else: err(f'abs is a {type(abs)}, but needs to be a string(path), File, or weird WLFunction thing' ) self.abspath = abs # this might change so they have to be functions # self.isfile = os.path.isfile(self.abspath) # self.isdir = os.path.isdir(self.abspath) self.mker = mker if mker: self.mkdirs() if w is not None: self.write(w) self.default_quiet = quiet self._default_default_quiet = None # for muffleing
def __init__(self, database, *args, allow_get=True, allow_set=True, password=None, **kwargs): apiFile = self.apifile_for(database.file) self.database = database self.allow_get = allow_get self.allow_set = allow_set self.password = password super().__init__(apiFile, *args, **kwargs) if not self.offline_mode: weval( If( wl.Not( wl.FileExistsQ( wl.CloudObject("APIPasswords", wlexpr("$CloudSymbolBase")))), wlexpr('CloudSymbol["APIPasswords"]=<||>'))) weval( wlexpr( f'pwds = CloudSymbol["APIPasswords"]; pwds["{apiFile.abspath}"] = "{self.password}"; CloudSymbol["APIPasswords"] = pwds;' )) else: warn( f'not pushing password for {self} because offline mode is switched one' ) apiFile.parent[f"{apiFile.name_pre_ext}_api_doc.text"].write( f"HTTP GET: {apiFile.wcurl}?<url encoded json obj>")