Skip to content

Commit

Permalink
output view
Browse files Browse the repository at this point in the history
  • Loading branch information
TGNThump committed May 2, 2018
1 parent 6b563e2 commit 6c5ea64
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 39 deletions.
18 changes: 10 additions & 8 deletions GroupProjectRASQL/Heuristics/Heuristic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public abstract class Heuristic : Reactive
{
protected Node root;
protected Node next;
protected bool isStarted = false;
public bool isComplete { get { return isStarted && remainingNodes.Count == 0; } }
public bool isStarted { get; private set; } = false;
public bool isComplete { get; private set; } = false;
public bool isEnabled { get; set; } = true;
public String name { get; protected set; }
public String description { get; protected set; }
Expand All @@ -38,23 +38,25 @@ public void Init() // init the heuristic

public void Step() // step through the currently active heuristic - called by ui button
{
if (!isEnabled) return;
if (!isStarted) Init();
if (isComplete) return;
if (IsComplete()) return;

Node next = remainingNodes.Dequeue();
if (next.IsRoot && next.IsLeaf) Step();
bool stop = Run(next);
if (!stop && !isComplete) Step();
if (!stop && !IsComplete()) Step();
}

public void Complete() // complete the currently active heurisitc - called by ui button
private bool IsComplete()
{
while (!isComplete) Step(); // while not done - step without interuptions
return isComplete = (isStarted && remainingNodes.Count == 0);
}

public void Reset()
public void Complete() // complete the currently active heurisitc - called by ui button
{
isStarted = false;
if (!isEnabled) return;
while (!IsComplete()) Step(); // while not done - step without interuptions
}

// Abstract method run for each Node in the tree.
Expand Down
5 changes: 4 additions & 1 deletion GroupProjectRASQL/View/src/components/components.vendor.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
import VueCodemirror from 'vue-codemirror'
Vue.use(VueCodemirror);
Vue.use(VueCodemirror);

import FontAwesomeIcon from '@fortawesome/vue-fontawesome'
Vue.component('font-awesome-icon', FontAwesomeIcon);
18 changes: 13 additions & 5 deletions GroupProjectRASQL/View/src/components/views/output.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,17 @@
<column lg="6">
<div v-if="model.CurrentHeuristic != null" class="row d-flex flex-row">
<column style="flex-grow: 0; padding-right: 0px;">
<button style="height: 100%; border-top-right-radius: 0px; border-bottom-right-radius: 0px; background-color: #F7F7F7;" class="btn btn-default">&lt;</button>
<!-- <button style="height: 100%; border-top-right-radius: 0px; border-bottom-right-radius: 0px; background-color: #F7F7F7;" class="btn btn-default">&lt;</button> -->
</column>
<column style="padding: 0px;">
<div class="card" style="margin-bottom: 0px; border-radius: 0px;">
<div class="card" style="margin-bottom: 0px;">
<!-- <div class="card" style="margin-bottom: 0px; border-radius: 0px;"> -->
<div class="card-header">{{model.CurrentHeuristic.name}}</div>
<div class="card-body">{{model.CurrentHeuristic.description}}</div>
</div>
</column>
<column style="flex-grow: 0; padding-left: 0px;">
<button style="height: 100%; border-top-left-radius: 0px; border-bottom-left-radius: 0px; background-color: #F7F7F7;" class="btn btn-default">&gt;</button>
<!-- <button style="height: 100%; border-top-left-radius: 0px; border-bottom-left-radius: 0px; background-color: #F7F7F7;" class="btn btn-default">&gt;</button> -->
</column>
</div>
<div class="row">
Expand All @@ -67,8 +68,15 @@
</column>
</div>
<div class="row">
<div v-for="heuristic in model.HeuristicList">
<div class="card" style="flex-grow: 0;"><div class="card-body"><pre>{{heuristic}}</pre></div></div>
<!-- <pre>{{model.HeuristicsArray}}</pre> -->
<div class="input-group mb-1" style="margin-bottom: 0px;" v-for="heuristic in model.HeuristicsArray">
<div class="input-group-prepend">
<div class="input-group-text">
<input type="checkbox" v-model="heuristic.isEnabled" aria-label="Checkbox for following text input">
</div>
</div>
<span class="form-control">{{heuristic.name}}</span>
<!-- <div class="card" style="flex-grow: 0;"><div class="card-body"><pre>{{heuristic}}</pre></div></div> -->
</div>
<!-- <div class="input-group mb-1" style="margin-bottom: 0px;">
<div class="input-group-prepend">
Expand Down
63 changes: 38 additions & 25 deletions GroupProjectRASQL/ViewModel/ApplicationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,9 @@ public class ApplicationViewModel : Reactive
Parser.Parser sqlParser = new Parser.Parser("sql");
Parser.Parser raParser = new Parser.Parser("ra");

public List<Heuristic> HeuristicList { get; private set; } = new List<Heuristic>();
public Heuristic[] HeuristicsArray { get; private set; }

public Heuristic CurrentHeuristic
{
get
{
if (HeuristicList.Count == 0) return null;
foreach (Heuristic heuristic in HeuristicList)
{
if (heuristic.isEnabled && !heuristic.isComplete) return heuristic;
}
return HeuristicList.Last();
}
}
public Heuristic CurrentHeuristic { get; private set; }

private string Parsed_SQL = "";
private string Parsed_RA_From_SQL = "";
Expand Down Expand Up @@ -175,12 +164,15 @@ public ApplicationViewModel()
new Heuristic0(ops).Complete();
HeuristicList.Clear();
HeuristicList.Add(new Heuristic1(ops));
HeuristicList.Add(new Heuristic2(ops));
HeuristicList.Add(new Heuristic3(ops));
HeuristicList.Add(new Heuristic4(ops));
HeuristicList.Add(new Heuristic5(ops));
HeuristicsArray = new Heuristic[] {
new Heuristic1(ops),
new Heuristic2(ops),
new Heuristic3(ops),
new Heuristic4(ops),
new Heuristic5(ops)
};
UpdateCurrentHeuristic();
this.OpsJSON = ops.Child().ToJSON().Replace("\"", "&quot;").Replace("'", "\"");
this.CurrentView = "output";
Expand All @@ -198,8 +190,10 @@ public ApplicationViewModel()
{
try
{
UpdateCurrentHeuristic();
if (CurrentHeuristic != null) CurrentHeuristic.Step();
this.OpsJSON = ops.Child().ToJSON().Replace("\"", "&quot;").Replace("'", "\"");
UpdateCurrentHeuristic();
}
catch (Exception e)
{
Expand All @@ -213,8 +207,10 @@ public ApplicationViewModel()
{
try
{
UpdateCurrentHeuristic();
if (CurrentHeuristic != null) CurrentHeuristic.Complete();
this.OpsJSON = ops.Child().ToJSON().Replace("\"", "&quot;").Replace("'", "\"");
UpdateCurrentHeuristic();
}
catch (Exception e)
{
Expand All @@ -239,12 +235,15 @@ public ApplicationViewModel()
new Heuristic0(ops).Complete();
HeuristicList.Clear();
HeuristicList.Add(new Heuristic1(ops));
HeuristicList.Add(new Heuristic2(ops));
HeuristicList.Add(new Heuristic3(ops));
HeuristicList.Add(new Heuristic4(ops));
HeuristicList.Add(new Heuristic5(ops));
HeuristicsArray = new Heuristic[] {
new Heuristic1(ops),
new Heuristic2(ops),
new Heuristic3(ops),
new Heuristic4(ops),
new Heuristic5(ops)
};
UpdateCurrentHeuristic();
this.OpsJSON = ops.Child().ToJSON().Replace("\"", "&quot;").Replace("'", "\"");
return;
Expand All @@ -258,6 +257,20 @@ public ApplicationViewModel()
});
}

void UpdateCurrentHeuristic()
{
if (HeuristicsArray == null) this.CurrentHeuristic = null;
foreach (Heuristic heuristic in HeuristicsArray)
{
if (heuristic.isEnabled && !heuristic.isComplete)
{
this.CurrentHeuristic = heuristic;
return;
}
}
this.CurrentHeuristic = HeuristicsArray.Last();
}

bool Squish(TreeNode<String> root)
{
if (root.Data.Equals("[string]") || root.Data.Equals("[field]"))
Expand Down

0 comments on commit 6c5ea64

Please sign in to comment.