在Scala.js中,代码如何检测它是在浏览器窗口中运行还是在WebWorker中运行?

时间:2019-03-13 00:06:52

标签: scala web-worker scala.js

通过普通的JavaScript,我们可以直接测试功能;看到: Reliably detect if the script is executing in a web worker

您如何通过Scala.js完成此任务?

1 个答案:

答案 0 :(得分:2)

正如Justin du Coeur所说,由于ScalaJS可以编译为JavaScript,因此您无法在JavaScript中做任何事情,而在ScalaJS中是做不到的。

因此,您会发现该代码看起来与您链接的代码异常相似:

d = {'field': ['longitude', 'altitude', 'location', 'date','check'], 
     'value': [100, 200.5, 'China', pd.Timestamp('20180303'), True]}

df = pd.DataFrame(d)
#print (df)

d = {"<class 'bool'>":"bool",
     "<class 'float'>":"float",
     "<class 'int'>":"int",
     "<class 'str'>":"string",
     "<class 'pandas._libs.tslibs.timestamps.Timestamp'>":"datetime"}
s = df['value'].apply(type).astype(str).map(d).fillna('not defined type')
df = df.join(df.set_index(s, append=True)['value'].unstack())
df['field_type'] = s
print (df)
       field                value  bool             datetime  float  int  \
0  longitude                  100   NaN                  NaN    NaN  100   
1   altitude                200.5   NaN                  NaN  200.5  NaN   
2   location                China   NaN                  NaN    NaN  NaN   
3       date  2018-03-03 00:00:00   NaN  2018-03-03 00:00:00    NaN  NaN   
4      check                 True  True                  NaN    NaN  NaN   

  string field_type  
0    NaN        int  
1    NaN      float  
2  China     string  
3    NaN   datetime  
4    NaN       bool  

DataFrame.join


我希望这会有所帮助。