Skip to content

Commit 9f9c7f5

Browse files
NathanNathan
authored andcommitted
sortbyweight
1 parent 09b608a commit 9f9c7f5

File tree

1 file changed

+53
-134
lines changed

1 file changed

+53
-134
lines changed

Catalog/Catlookup.cs

Lines changed: 53 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ public static LoomedFabric ParsePosts(_LoadedBoardFabric boardfabric)
257257
}
258258
Console.WriteLine("parse checkpoint 3");
259259

260-
SortedDisplayList = replysort(postarray, replytree);
260+
// SortedDisplayList = replysort(postarray, replytree);
261+
SortedDisplayList = Sortbyweight(postarray, replytree);
261262
// SortedDisplayList = postarray;
262263

263264
DisplayThread finishedThread = new DisplayThread(OPpostID, boardfabric.Board, SortedDisplayList, OPSub, boardfabric.LThreads[i].Weight);
@@ -371,115 +372,6 @@ public static string GetBoard()
371372
return System.Console.ReadLine();
372373
}
373374

374-
public static Shell32.Folder GetShell32NameSpaceFolder(Object folder)
375-
{
376-
Type shellAppType = Type.GetTypeFromProgID("Shell.Application");
377-
378-
Object shell = Activator.CreateInstance(shellAppType);
379-
return (Shell32.Folder)shellAppType.InvokeMember("NameSpace",
380-
System.Reflection.BindingFlags.InvokeMethod, null, shell, new object[] { folder });
381-
}
382-
383-
public static string GetExtendedFileProperty(string filePath, string propertyName)
384-
{
385-
string value = string.Empty;
386-
string baseFolder = Path.GetDirectoryName(filePath);
387-
string fileName = Path.GetFileName(filePath);
388-
389-
//Method to load and execute the Shell object for Windows server 8 environment otherwise you get "Unable to cast COM object of type 'System.__ComObject' to interface type 'Shell32.Shell'"
390-
Type shellAppType = Type.GetTypeFromProgID("Shell.Application");
391-
Object shell = Activator.CreateInstance(shellAppType);
392-
Shell32.Folder shellFolder = (Shell32.Folder)shellAppType.InvokeMember("NameSpace", System.Reflection.BindingFlags.InvokeMethod, null, shell, new object[] { baseFolder });
393-
394-
//Parsename will find the specific file I'm looking for in the Shell32.Folder object
395-
Shell32.FolderItem folderitem = shellFolder.ParseName(fileName);
396-
if (folderitem != null)
397-
{
398-
for (int i = 0; i < short.MaxValue; i++)
399-
{
400-
//Get the property name for property index i
401-
string property = shellFolder.GetDetailsOf(null, i);
402-
403-
//Will be empty when all possible properties has been looped through, break out of loop
404-
if (String.IsNullOrEmpty(property)) break;
405-
406-
//Skip to next property if this is not the specified property
407-
if (property != propertyName) continue;
408-
409-
//Read value of property
410-
value = shellFolder.GetDetailsOf(folderitem, i);
411-
}
412-
}
413-
//returns string.Empty if no value was found for the specified property
414-
return value;
415-
}
416-
417-
418-
public static Tree repliesnew(string postContent, Tree replytree, int postID)
419-
{
420-
Console.WriteLine(postContent + " content");
421-
//IDictionary<int,int> postreplies = new IDictionary<int,int>();
422-
// replytree.addNode(postID);
423-
424-
// Regex IDfind = new Regex();
425-
426-
if (postContent.Contains(">>") && postContent.Contains(" "))
427-
{
428-
int Start, End;
429-
int data = 1;
430-
string datacheck = "";
431-
int lastreply = 1;
432-
bool crossthread = false;
433-
Start = postContent.IndexOf(">>", 0) + 2;
434-
435-
436-
do
437-
{
438-
End = postContent.IndexOf(" ", Start);
439-
datacheck = postContent.Substring(Start, End - Start);
440-
441-
if (datacheck.IndexOf(">") != -1)
442-
{
443-
Console.WriteLine("crossthread detected");
444-
crossthread = true;
445-
446-
}
447-
data = Int32.Parse(postContent.Substring(Start, End - Start));
448-
Console.WriteLine(data + " data");
449-
450-
451-
452-
453-
if (replytree.getNode(data) == null && data != 0) //new unique reply
454-
{
455-
Node newroot = new Node();
456-
newroot.id = data;
457-
// newroot.a(data);
458-
replytree.addRoot(newroot);
459-
lastreply = data;
460-
461-
}
462-
else if (replytree.getNode(data) != null && data != lastreply) //parent node contained in tree already
463-
{
464-
Node newnode = new Node();
465-
newnode.id = data;
466-
newnode.addParent(data);
467-
replytree.addNode(newnode);
468-
lastreply = data;
469-
}
470-
471-
Start = postContent.IndexOf(">>", End) + 2;
472-
crossthread = false;
473-
474-
}
475-
while (Start != 1);
476-
477-
// return replytree;
478-
}
479-
// replytree.addNode(postID); //end amend
480-
return replytree;
481-
}
482-
483375
public static Tree replies(string postContent, Tree replytree, int postID, int postW)
484376
{
485377
string pattern = "(?<=>>)(((?<!>>>)[0-9]))+";
@@ -573,53 +465,71 @@ public static List<_Pbox> Sortbyweight(List<_Pbox> unsorted, Tree replytree)
573465
List<Dictionary<int, int>> paths = new List<Dictionary<int, int>>();
574466

575467

576-
foreach (_Pbox upost in unsorted)
468+
foreach (Node Root in replytree.getRoots()) //for each original root post
577469
{
470+
List<Dictionary<int, int>> pathwaylist = new List<Dictionary<int, int>>(); //this nodes combined pathway dict
578471

579472

580-
if (upost.ReplyDepth == 0) //if post is original root post
581-
{
582-
583-
if (replytree.getNode(upost.PostID) == null) //replytree id is null
584-
{
585-
586-
}
587-
else
588-
{
589-
Node currentnode = replytree.getNode(upost.PostID); //reply tree node is ok
590-
paths = NodePaths(currentnode,replytree);
473+
List<Dictionary<int, int>> pathwaysfromroot = NodePaths(Root, replytree, pathwaylist, null); //grab all pathways in list
591474

592-
}
593-
594-
595-
}
596-
else //if the post is a reply
597-
{
598475

599-
}
476+
//ratio each pathway and keep top 3
477+
// List<Dictionary<int,int>> ratioedpaths = RatioMethod(pathwaysfromroot);
478+
// SortedPosts = PathsToBox(ratioedpaths);
600479

601480
}
602481

603-
482+
return SortedPosts;
604483

605484
}
606-
public static List<Dictionary<int,int>> NodePaths(Node cnode, Tree replytree)
485+
public static List<Dictionary<int, int>> NodePaths(Node cnode, Tree replytree, List<Dictionary<int, int>> pathwaylist, Dictionary<int, int> RP)
607486
{
608487
Dictionary<int, int> rollingpath = new Dictionary<int, int>();
609488

489+
if(RP != null)
490+
{
491+
rollingpath = RP;
492+
}
493+
494+
610495
List<Node> kids = cnode.getchildren();
496+
if (rollingpath.ContainsKey(cnode.id))
497+
{
498+
//node already exists in pathway, cycle detected
499+
500+
pathwaylist.Add(rollingpath); //add completed path to pathlist
501+
502+
503+
}
504+
else
505+
{
506+
507+
rollingpath.Add(cnode.id, cnode.replyweight);// add parent node to pathway
508+
509+
}
611510

612-
rollingpath.Add(cnode.id, cnode.replyweight);// first reply in chains,
613511

614-
foreach (Node child in kids)
512+
513+
if(cnode.getchildren().Equals(new List<Node>()) == true) // get children returns an empty list c0 termination
615514
{
515+
pathwaylist.Add(rollingpath); //add completed path to pathlist
516+
}
616517

518+
foreach (Node child in kids) // create cN new dictonary paths
519+
{
520+
pathwaylist = NodePaths(child, replytree, pathwaylist, rollingpath);
617521

618522

619523
}
620-
524+
525+
return pathwaylist;
621526

622527
}
528+
529+
530+
531+
532+
623533
public static List<_Pbox> childloop(int post, Tree replytree, List<_Pbox> SortedPosts, List<_Pbox> UnsortedPosts)
624534
{
625535

@@ -1170,6 +1080,15 @@ public void addRoot(Node node) // adds node to root list, and adds node to node
11701080
this.roots.Add(node);
11711081
node.tree = this;
11721082
}
1083+
public List<Node> getRoots()
1084+
{
1085+
if(roots != null)
1086+
{
1087+
return roots;
1088+
}
1089+
return null;
1090+
}
1091+
11731092

11741093
}
11751094

0 commit comments

Comments
 (0)