internal static IEnumerable <SearchItem> References(SearchRequest selectRequest, SearchExpressionNode node, IEnumerable <SearchItem> items) { var objectType = node.GetProperty <string>("type", null); var refDepth = node.GetProperty("depth", 1); return(items.SelectMany(item => selectRequest.SelectReferences(item, objectType, refDepth))); }
private void DrawSelectAssetEditor() { var derivedTypeInfo = GetDerivedTypeInfo(typeof(UnityEngine.Object)); var typeName = m_Node.GetProperty <string>("type", null); var selectedTypeIndex = derivedTypeInfo.names.FindIndex(n => n == typeName); var typeLabel = selectedTypeIndex == -1 ? null : derivedTypeInfo.labels[selectedTypeIndex]; DrawSelectionPopup("Type", typeLabel ?? "Select type...", derivedTypeInfo.labels, selectedIndex => { m_Node.SetProperty("type", derivedTypeInfo.names[selectedIndex]); propertiesChanged?.Invoke(m_Node); }); if (typeName != null) { if (selectedTypeIndex != -1) { var selectedType = derivedTypeInfo.types[selectedTypeIndex]; var properties = GetTypePropertyNames(selectedType); var propertyName = m_Node.GetProperty <string>("field", null); var propertyLabel = properties.FirstOrDefault(p => p.name == propertyName).label; DrawSelectionPopup("Property", propertyLabel ?? "Select property...", properties.Select(p => p.label), selectedIndex => { m_Node.SetProperty("field", properties[selectedIndex].name); propertiesChanged?.Invoke(m_Node); }); } } }
internal static IEnumerable <SearchItem> Object(SearchRequest selectRequest, SearchExpressionNode node, IEnumerable <SearchItem> items) { var objectType = node.GetProperty <string>("type", null); var propertyName = node.GetProperty <string>("field", null); var mapped = node.GetProperty(ExpressionKeyName.Mapped, false); var overrides = node.GetProperty(ExpressionKeyName.Overrides, true); return(items.SelectMany(item => selectRequest.SelectObject(item, objectType, propertyName, mapped, overrides))); }
private SearchRequest BuildSelectRequest(SearchExpressionNode node) { if (node.source == null) { return(SearchRequest.empty); } var sourceRequest = BuildRequest(node.source); var selectField = node.selectField; var objectType = node.GetProperty <string>("type", null); var propertyName = node.GetProperty <string>("field", null); return(sourceRequest.Select(selectField, objectType, propertyName)); }
public void UpdateNode(SearchExpressionNode ex) { if (!TryGetNode(ex, out var node)) { return; } node.title = FormatTitle(ex); // Update result port if (ex.type == ExpressionType.Value || ex.type == ExpressionType.Provider) { var outputPort = FindPort(node, "output"); if (outputPort != null) { outputPort.portName = Convert.ToString(ex.value); } } else if (ex.type == ExpressionType.Union) { UpdateUnionVariables(node); } else if (ex.type == ExpressionType.Select) { var outputPort = FindPort(node, "output"); if (outputPort != null) { outputPort.portName = ex.GetProperty("field", "Results"); } } NotifyGraphChanged(); }
private static string GetSelectNodeOutputPortName(SearchExpressionNode ex) { var propertyName = ex.GetProperty("field", "Results"); if (propertyName.StartsWith("m_", StringComparison.Ordinal)) { propertyName = propertyName.Substring(2); } return(propertyName); }
private void DrawMapEditor() { var mapping = (Mapping)m_Node.GetProperty(nameof(Mapping), (int)Mapping.Count); var groupBy = m_Node.GetProperty(ExpressionKeyName.GroupBy, ""); EditorGUI.BeginChangeCheck(); mapping = (Mapping)EditorGUILayout.EnumPopup(nameof(Mapping), mapping); if (m_Node.TryGetVariableSource(ExpressionKeyName.X, out var xSource) && xSource != null && mapping != Mapping.Table) { groupBy = EditorGUILayout.DelayedTextField("Group By", groupBy); } else { GUILayout.Space(20); } if (EditorGUI.EndChangeCheck()) { m_Node.SetProperty(nameof(Mapping), (int)mapping); m_Node.SetProperty(ExpressionKeyName.GroupBy, groupBy); propertiesChanged?.Invoke(m_Node); } }
private void AddPorts(Node node, SearchExpressionNode ex) { switch (ex.type) { case ExpressionType.Search: AddInputPort(node, $"source-{ex.id}", "Source", typeof(ExpressionSource)); AddVariablePorts(node, ex); AddOutputPort(node, $"output-{ex.id}", "Results", typeof(ExpressionSet)); break; case ExpressionType.Expression: AddOutputPort(node, $"output-{ex.id}", "Results", typeof(ExpressionSet)); break; case ExpressionType.Select: AddInputPort(node, $"source-{ex.id}", "Source", typeof(ExpressionResults)); AddOutputPort(node, $"output-{ex.id}", ex.GetProperty("field", "Results"), typeof(ExpressionSet)); break; case ExpressionType.Results: AddInputPort(node, $"source-{ex.id}", "Source", typeof(ExpressionResults)); break; case ExpressionType.Provider: AddOutputPort(node, $"output-{ex.id}", Convert.ToString(ex.value), typeof(ExpressionProvider)); break; case ExpressionType.Value: AddOutputPort(node, $"output-{ex.id}", Convert.ToString(ex.value), typeof(ExpressionConstant)); break; case ExpressionType.Union: var nextMergeInputPortName = (ex.GetVariableCount() + 1).ToString(); AddVariablePorts(node, ex); AddInputPort(node, $"var-{ex.id}-{nextMergeInputPortName}", nextMergeInputPortName, typeof(ExpressionVariable)); AddOutputPort(node, $"output-{ex.id}", "Results", typeof(ExpressionSet)); break; case ExpressionType.Intersect: case ExpressionType.Except: AddInputPort(node, $"source-{ex.id}", "Source", typeof(ExpressionResults)); AddInputPort(node, $"var-{ex.id}-With", "With", typeof(ExpressionVariable)); AddOutputPort(node, $"output-{ex.id}", "Results", typeof(ExpressionSet)); break; default: throw new NotSupportedException($"Expression {ex.type} {ex.id} has no support ports"); } node.RefreshPorts(); }
private string FormatTitle(SearchExpressionNode ex) { switch (ex.type) { case ExpressionType.Value: return(ex.name ?? ex.type.ToString()); case ExpressionType.Search: return(Convert.ToString(ex.value)); case ExpressionType.Select: return($"{ex.type} {ex.GetProperty("type", Convert.ToString(ex.value))}"); } return(ex.type.ToString()); }
private string FormatTitle(SearchExpressionNode ex) { switch (ex.type) { case ExpressionType.Expression: return(ex.value != null?System.IO.Path.GetFileNameWithoutExtension(Convert.ToString(ex.value)) : ex.type.ToString()); case ExpressionType.Value: return(ex.name ?? ex.type.ToString()); case ExpressionType.Search: if (String.IsNullOrEmpty(ex.name)) { return(Convert.ToString(ex.value)); } return(ex.name); case ExpressionType.Select: return($"{ex.type} {ex.GetProperty("type", Convert.ToString(ex.value))}"); } return(ex.type.ToString()); }
private SearchRequest BuildMappingRequest(SearchExpressionNode node) { var mapping = (Mapping)node.GetProperty(nameof(Mapping), (int)Mapping.Count); var groupBy = node.GetProperty(ExpressionKeyName.GroupBy, ""); if (node.TryGetVariableSource(ExpressionKeyName.X, out var xSource) && String.IsNullOrWhiteSpace(groupBy)) { Debug.LogWarning($"Group by {mapping} mapping not defined for {node.name ?? node.id}."); return(SearchRequest.empty); } var grouping = xSource != null; if (!node.TryGetVariableSource(ExpressionKeyName.Y, out var ySource)) { Debug.LogWarning($"No data source (Y) set for {node.name ?? node.id}."); return(SearchRequest.empty); } else if (grouping && ySource.type == ExpressionType.Select && !ySource.GetProperty(ExpressionKeyName.Mapped, false)) { Debug.LogWarning($"Mapping data source for {node.name ?? node.id} must be a search node (currently a {ySource.type} node)"); if (ySource.source?.type == ExpressionType.Search) { ySource = ySource.source; } } var mappingRequest = new SearchRequest(node.type); if (mapping == Mapping.Table) { if (xSource == null) { Debug.LogWarning($"No data source (X) set for {node.name ?? node.id}."); return(SearchRequest.empty); } var xRequest = BuildRequest(xSource); var yRequest = BuildRequest(ySource); mappingRequest.DependsOn(xRequest); mappingRequest.DependsOn(yRequest); bool fetchSourceX = false; var xItems = new List <SearchItem>(); xRequest.Resolve(results => xItems.AddRange(results), exs => fetchSourceX = true); bool fetchSourceY = false; var yItems = new List <SearchItem>(); yRequest.Resolve(results => yItems.AddRange(results), exs => fetchSourceY = true); mappingRequest.resolved += _ => { if (!fetchSourceX || !fetchSourceY) { throw new ExpressionException(node, "Table mapping wasn't resolved properly"); } int xIndex = 0; foreach (var x in xItems) { var y = yItems.Count >= 0 && xIndex < yItems.Count ? yItems[xIndex].value : null; if (y != null && !(y is double) && double.TryParse(y.ToString(), out var d)) { y = d; } x.value = new MappingData() { type = Mapping.Table, value = y, query = xSource.GetProperty(ExpressionKeyName.BakedQuery, x.context?.searchQuery) }; x.description = $"{y}"; ++xIndex; } mappingRequest.ProcessItems(xItems); }; } else { var groupsRequest = BuildRequest(xSource ?? new SearchExpressionNode(ExpressionType.Value, null, "")); var groups = new Dictionary <string, List <object> >(); mappingRequest.DependsOn(groupsRequest); groupsRequest.Resolve(items => { foreach (var item in items) { var groupName = grouping ? item.id : node.name ?? mapping.ToString(); var groupQuery = grouping ? $"({ySource.value}) {groupBy}={groupName}" : ySource.value as string; var groupSource = grouping ? new SearchExpressionNode(ySource.type, ySource.source, groupQuery, ySource.variables) : ySource; var groupRequest = BuildRequest(groupSource); mappingRequest.DependsOn(groupRequest); groupsRequest.DependsOn(groupRequest); if (!groups.ContainsKey(groupName)) { groups[groupName] = new List <object>(); } var groupData = groups[groupName]; var totalCount = 0.0; var totalValue = 0.0; groupRequest.Resolve(groupItems => { switch (mapping) { case Mapping.Min: UpdateMappingMin(groupData, groupItems); break; case Mapping.Max: UpdateMappingMax(groupData, groupItems); break; case Mapping.Average: UpdateMappingAverage(groupData, groupItems, ref totalCount, ref totalValue); break; case Mapping.Count: UpdateMappingCount(groupData, groupItems); break; } }, _ => { mappingRequest.ProcessItems(groupData.OrderBy(e => e).Select(e => new SearchItem(xSource == null ? e?.ToString() : groupName) { score = double.TryParse(groupName, out var d) ? -(int)d : groupName.GetHashCode(), label = groupName, description = e?.ToString(), value = new MappingData() { type = mapping, value = e, query = groupSource.GetProperty(ExpressionKeyName.BakedQuery, groupQuery) } })); }); } }, null);