我有一个案例类,其中有两个字段Seq[Objects]。这两个对象属于两个不同的案例类。
case class Passport(country: String, name: String)
case class DrivingLicence(code: String, name: String)
case class Docs(passports : Seq[Passport], driv: Seq[DrivingLicence])
val pass1 = Passport("UK", "Michael")
val pass2 = Passport("USA", "Michael")
val driv1 = DrivingLicence("A2", "Mich")
val driv2 = DrivingLicence("A4", "Mich")
val docs = Docs(Seq(pass1,pass2), Seq(driv1,driv2))
Run Code Online (Sandbox Code Playgroud)
我可以生成具有所有属性及其类型的地图,如下所示:
val r = currentMirror.reflect(docs)
val mapType = r.symbol.typeSignature.members.toStream
.collect{case s : TermSymbol if !s.isMethod => r.reflectField(s)}
.map(r => r.symbol.name.toString.trim -> r.symbol.typeSignature)
.toMap
println("Map of Types: "+mapType)
Run Code Online (Sandbox Code Playgroud)
输出为:
地图类型:地图(driv-> Seq [DrivingLicence],护照-> Seq [Passport]) …
是否可以在不读取控制台日志的情况下检测在 Unity 中运行的 C# 脚本中的错误?当我必须构建游戏并在手机上测试时,我需要这个。如果运行时出现错误,它将显示一个显示错误的消息框。
我知道我们可以使用 Unity Log Viewer 打印设备中的所有日志。但我要求另一种方法来做到这一点。我问一个更简单的解决方案。我的解决方案我认为最好在编辑器中成功运行时检测小错误,但在设备中运行时会出现问题,因为它只显示 showMessageBox 错误。
我需要检测运行时是否有问题。我意识到有 Debug.LogError 我们可以检测到错误。但是 Debug.LogError 只是由我们打印消息类型来指出对象错误是什么。我需要的是检测像控制台这样的全局错误并显示来自统一引擎的错误消息。
我需要的可能是这样的:
void Update() {
showMessageBox(isErrorDetect());
}
showMessageBox => is a function to show message box.
isErrorDetect => this will print an error if detect like a console.
Run Code Online (Sandbox Code Playgroud)
如果有人明白我的意思,那么请给我一个解决方案。
谢谢你
我想知道是否有地方可以下载给定股票的元数据。我之前正在研究 REST API,我想我也许可以使用这样的东西:
stock_code = "GME"
base_url = "https://somestockmarkekpage.com/api/stock?code={}"
resp = requests.get(base_url.format(stock_code))
print(resp.json()['short_ratio'])
Run Code Online (Sandbox Code Playgroud)
问题是我不知道可以从哪里下载这些数据的任何base_url,甚至不知道它是否免费存在。但是,我们非常欢迎您提供任何其他 API 或服务
我正在使用 GVRTeleport 脚本来允许使用纸板应用程序进行传送。我希望用于传送的光线投射忽略除一层之外的所有层。通过此页面,我相应地修改了脚本(抱歉,找不到此代码所有者的原始链接),但现在传送脚本什么也看不到。有任何想法吗?我的地板层是第 8 层,这是我希望此光线投射与之交互的层。
using UnityEngine;
public class GVRTeleport : MonoBehaviour {
public float viewHeight = 7f;
Vector3 fwd;
public float maxDistance = 10f;
public LineRenderer line;
public GameObject parent;
public GameObject targetIndicator;
public StraightLineParam genLine;
int layerMask = 1 << 8;
void Start() {
}
void Update() {
RaycastHit hit;
Ray ray;
if (Physics.Raycast (transform.position, Vector3.forward, Mathf.Infinity, layerMask)) {
Debug.Log ("The ray hit the floor");
if (debugWithMouse) {
Vector2 mousePos = new Vector2 (Input.mousePosition.x / Screen.width, …Run Code Online (Sandbox Code Playgroud) 我试图获得单列数据帧的0.8百分位数.我试过这样的方式:
val limit80 = 0.8
val dfSize = df.count()
val perfentileIndex = dfSize*limit80
dfSorted = df.sort()
val percentile80 = dfSorted .take(perfentileIndex).last()
Run Code Online (Sandbox Code Playgroud)
但我认为这对大型数据帧来说是失败的,因为它们可能分布在不同的节点上.
有没有更好的方法来计算百分位数?或者我怎么能在同一台机器中拥有数据帧的所有行(即使这是非常反模式的),所以这df.take(index)将真正考虑整个数据集而不仅仅是节点中的分区.
所以我有一堂课:
case class Document (idx: String, name: String, code: String)
Run Code Online (Sandbox Code Playgroud)
由于进行了一些转换,最初创建为Document的对象现在变为Any类型。
val doc = Document("12", "anyName", "ps") // Ends up as type Any
Run Code Online (Sandbox Code Playgroud)
所以我想Document再次将其转换为类型。
我知道可以这样做:
val docNew = doc.asInstanceOf[Document]
Run Code Online (Sandbox Code Playgroud)
但是,我正在尝试的是在这种情况下将类型Document作为参数传递,以使其更通用。
因此,我尝试以下操作:
val mType = Document
val docNew = doc.asInstanceOf[mType]
Run Code Online (Sandbox Code Playgroud)
但是Intellij说:
无法解析符号mType
编辑:我的最终目标是将参数Document传递给函数,因此最终我可以做类似的事情:
def convertIntoDoc(doc: Any, mType: Type) = {
val docNew = doc.asInstanceOf[mType]
docNew
}
Run Code Online (Sandbox Code Playgroud) 如何在课堂上创建字符串数组?
此外,我必须向该数组添加或附加值。
我可以使用 Firebase 实时数据库将数组值存储在数据库中。
不是特定的键。
我将数组声明为:
private string[] uiddata;
Run Code Online (Sandbox Code Playgroud)
该数组用于 for 循环并将元素添加到数组中
public void Click()
{
_uid = int.Parse(_uidText.text);
for(int i = 0; i < uiddata.Length;i++)
{
uiddata.Add(_uid);
//_score = int.Parse(_scoreText.text);
_uidRef.SetValueAsync(_uid);
//_scoreRef.SetValueAsync(_score);
_uidRef.RunTransaction(data =>
{
data.Value =_uid ;
return TransactionResult.Success(data);
}).ContinueWith(task =>
{
if (task.Exception != null)
Debug.Log(task.Exception.ToString());
});
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的脚本中,我尝试将我的值添加到数组中,但出现此错误:
错误 CS1061:类型
string[]不包含定义Add并且找不到Add类型的扩展方法string[]。您是否缺少程序集参考?
我正在为 Hololens 2 构建一个 Unity 项目,该项目使用System.Numerics来自.NET
我按原样从 git 导入了这个项目,但遇到了一些类似于以下内容的错误:
System.Numerics.Matrix4x4 converted4x4LocationMatrix = ConvertRightHandedMatrix4x4ToLeftHanded(suObject.GetLocationAsMatrix());
error CS7069: Reference to type 'Matrix4x4' claims it is defined in 'System.Numerics', but it could not be found
Run Code Online (Sandbox Code Playgroud)
System.Numerics似乎也缺少Vector3课程Vector2。
该项目已有几年历史,因此我使用的 Unity 版本可能需要更改配置中的某些内容,以使其与存在的“System.Numerics”版本兼容Matrix4x4。有谁知道如何解决这一问题?
我正在使用Unity 2019.2.4f1与Windows Build Support IL2CPP.
将字符串转换为十进制 (18,2)
from pyspark.sql.types import *
DF1 = DF.withColumn("New_col", DF["New_col"].cast(DecimalType(12,2)))
display(DF1)
Run Code Online (Sandbox Code Playgroud)
需要帮助将字符串转换为十进制以将 DF 加载到数据库中。