Example #1
0
        static bool TryRequestVersionTag(RepoApi api, [MaybeNullWhen(false)] out string tag)
        {
            tag = null;
            ReadonlyHashset <string> tags = api.Tags;

            do
            {
                Console.Write("> ");
                var answer = Console.ReadLine().Trim();
                if (string.IsNullOrEmpty(answer))
                {
                    return(false);
                }

                if (tags.Contains(answer))
                {
                    tag = answer;
                    return(true);
                }

                Console.WriteLine("No exact match found, closest matches:");
                ILookup <int, string> grouped = tags.ToLookup(t =>
                                                              t.StartsWith(answer)
                    ? 0
                    : t.Contains(answer)
                    ? 1
                    : 2
                                                              );

                Console.WriteLine(string.Join(", ",
                                              grouped[0].Concat(grouped[1]).Concat(
                                                  grouped[2]
                                                  .Select(
                                                      t => (
                                                          tag: t,
                                                          dist: StringHelpers.EditDistance(answer, t)
                                                          )
                                                      )
                                                  .Where(t => t.dist < 4)
                                                  .OrderBy(t => t.dist)
                                                  .Select(t => t.tag)
                                                  )
                                              ));
            } while (true);
        }
Example #2
0
        /// <summary> Show an estimated countdown to a region's next update </summary>
        public async Task Run(string userAgent, Dictionary <string, string> userTags, bool interactiveLog = false)
        {
            dump = RepoRegionDump.Dump(userAgent, userTags);
            api  = RepoApi.Api(userAgent);

            var regions = await dump.Regions(interactiveLog);

            var targetIndex = -1;

            // Get index of target region in list from dump
            targetIndex = regions.FindIndex(r =>
                                            string.Equals(r.Name, targetRegion,
                                                          StringComparison.InvariantCultureIgnoreCase));
            if (targetIndex < 0)
            {
                throw new Exception("Target region not found");
            }

            target = regions[targetIndex];

            // A boolean indicating if the next update is major (true) or minor (false)
            nextUpdateIsMajor = TimeUtil.UnixLastMajorStart() < TimeUtil.UnixLastMinorStart();

            // Length of the last update in seconds
            var lastUpdateTook = nextUpdateIsMajor
                ? await dump.MajorTook()
                : await dump.MinorTook();

            // Select the most appropriate triggers for the target, given the length of the last update
            await Triggers(targetIndex, regions, lastUpdateTook);

            // For each trigger, an average "seconds-per-nation" value is calculated and appended to this list. As the
            // update goes faster or slower, these averages will change in between triggers. This can then be used
            // to determine variance (unpredictability of the update), which the user can use to better determine how
            // much risk they can take.
            secondsPerNation = new List <double>
            {
                // The first seconds-per-nation value is taken from the previous update
                nextUpdateIsMajor?await dump.MajorTick() : await dump.MinorTick()
            };

            // Watch the triggers and target to adjust seconds-per-nation and exit when target updates
            await WatchTriggers();
        }
Example #3
0
File: Ops.cs Project: bion33/Kronos
        /// <summary> Generate a report of likely military operations during the last (major or minor) update </summary>
        public async Task Run(string userAgent, Dictionary <string, string> userTags, bool interactiveLog = false)
        {
            Console.Write("Compiling operations report... \n");

            api     = RepoApi.Api(userAgent);
            regions = await RepoRegionDump.Dump(userAgent, userTags).Regions();

            // Start and end of last (major or minor) update
            var updateStart = StartOfLastUpdate();
            var updateEnd   = await api.LastUpdateFor(regions.Last().Name);

            // Get happenings
            var delegateChangeHappenings = await api.DelegateChangesFrom(updateStart, updateEnd);

            // Parse each happening to the DelegacyChange DTO
            var delegacyChanges = DelegacyChanges(delegateChangeHappenings);

            // Filter out the suspicious changes from among the (supposedly) legitimate changes
            var ops = await FilterOps(delegacyChanges, updateEnd - 43200, userTags, interactiveLog);

            if (interactiveLog)
            {
                Console.Write("Saving to report... ");
            }

            // Generate report
            ops = ops.OrderBy(o => o.ChangeTimeStamp).ToList();
            var report = Report(ops);

            // Save
            var date = TimeUtil.DateForPath();

            Directory.CreateDirectory(date);
            await File.WriteAllTextAsync($"{date}/Kronos-Ops_{date}.md", report);

            if (interactiveLog)
            {
                Console.Write("[done].\n");
            }
        }
Example #4
0
 public static Ice.DispatchStatus typeName___(RepoApi obj__, IceInternal.Incoming inS__, Ice.Current current__)
 {
     checkMode__(Ice.OperationMode.Idempotent, current__.mode);
     IceInternal.BasicStream is__ = inS__.istr();
     is__.startReadEncaps();
     string id;
     id = is__.readString();
     is__.endReadEncaps();
     IceInternal.BasicStream os__ = inS__.ostr();
     string ret__ = obj__.typeName(id, current__);
     os__.writeString(ret__);
     return Ice.DispatchStatus.DispatchOK;
 }
Example #5
0
 public static Ice.DispatchStatus setTo___(RepoApi obj__, IceInternal.Incoming inS__, Ice.Current current__)
 {
     checkMode__(Ice.OperationMode.Normal, current__.mode);
     IceInternal.BasicStream is__ = inS__.istr();
     is__.startReadEncaps();
     string id;
     id = is__.readString();
     string to;
     to = is__.readString();
     is__.endReadEncaps();
     obj__.setTo(id, to, current__);
     return Ice.DispatchStatus.DispatchOK;
 }
Example #6
0
 public static Ice.DispatchStatus setProperty___(RepoApi obj__, IceInternal.Incoming inS__, Ice.Current current__)
 {
     checkMode__(Ice.OperationMode.Normal, current__.mode);
     IceInternal.BasicStream is__ = inS__.istr();
     is__.startReadEncaps();
     string id;
     id = is__.readString();
     string propertyName;
     propertyName = is__.readString();
     string value;
     value = is__.readString();
     is__.endReadEncaps();
     obj__.setProperty(id, propertyName, value, current__);
     return Ice.DispatchStatus.DispatchOK;
 }
Example #7
0
 public static Ice.DispatchStatus save___(RepoApi obj__, IceInternal.Incoming inS__, Ice.Current current__)
 {
     checkMode__(Ice.OperationMode.Normal, current__.mode);
     inS__.istr().skipEmptyEncaps();
     obj__.save(current__);
     return Ice.DispatchStatus.DispatchOK;
 }
Example #8
0
 public static Ice.DispatchStatus otherEntityFromLink___(RepoApi obj__, IceInternal.Incoming inS__, Ice.Current current__)
 {
     checkMode__(Ice.OperationMode.Idempotent, current__.mode);
     IceInternal.BasicStream is__ = inS__.istr();
     is__.startReadEncaps();
     string linkId;
     linkId = is__.readString();
     string firstNode;
     firstNode = is__.readString();
     is__.endReadEncaps();
     IceInternal.BasicStream os__ = inS__.ostr();
     string ret__ = obj__.otherEntityFromLink(linkId, firstNode, current__);
     os__.writeString(ret__);
     return Ice.DispatchStatus.DispatchOK;
 }
Example #9
0
 public static Ice.DispatchStatus hasProperty___(RepoApi obj__, IceInternal.Incoming inS__, Ice.Current current__)
 {
     checkMode__(Ice.OperationMode.Idempotent, current__.mode);
     IceInternal.BasicStream is__ = inS__.istr();
     is__.startReadEncaps();
     string id;
     id = is__.readString();
     string propertyName;
     propertyName = is__.readString();
     is__.endReadEncaps();
     IceInternal.BasicStream os__ = inS__.ostr();
     bool ret__ = obj__.hasProperty(id, propertyName, current__);
     os__.writeBool(ret__);
     return Ice.DispatchStatus.DispatchOK;
 }
Example #10
0
 public static Ice.DispatchStatus children___(RepoApi obj__, IceInternal.Incoming inS__, Ice.Current current__)
 {
     checkMode__(Ice.OperationMode.Normal, current__.mode);
     IceInternal.BasicStream is__ = inS__.istr();
     is__.startReadEncaps();
     string id;
     id = is__.readString();
     is__.endReadEncaps();
     IceInternal.BasicStream os__ = inS__.ostr();
     string[] ret__ = obj__.children(id, current__);
     os__.writeStringSeq(ret__);
     return Ice.DispatchStatus.DispatchOK;
 }
Example #11
0
        static void Main(string[] _)
        {
            // TODO: Catch excptions

            if (!ModulesList.TryLoadFromConsole(out ModulesList? modules, out string path))
            {
                Console.WriteLine("Generation cancelled");
                return;
            }
            Console.WriteLine("modules.json successfully loaded");

            if (!modules.TryGetLocalModule(ref path, "phi.structure", out Module? structureModule, "datapack"))
            {
                Console.WriteLine("The phi.structure module does not exist as a local module in this project, cancelling generation");
                return;
            }

            Console.WriteLine("phi.structure module successfully located");

            Console.WriteLine("Fetching MCData");
            using var api = RepoApi.Load(remoteUrl, "mcdata");
            Console.WriteLine("MCData succesfully loaded");

            var blockMapFile = Path.Combine(path, "src", blockMapFileName);

            BlockMap blockMap;

            if (!File.Exists(blockMapFile))
            {
                Console.WriteLine("No existing block map file, please enter first version to support");
                if (!TryRequestVersionTag(api, out string?latestVersion))
                {
                    Console.WriteLine("Cancelling generation");
                    return;
                }
                blockMap = new BlockMap
                {
                    LatestVersion = latestVersion
                };
            }
            else
            {
                BlockMap?loadedBlockMap = JsonConvert.DeserializeObject <BlockMap>(File.ReadAllText(blockMapFile), new JsonSerializerSettings
                {
                    ContractResolver = new DefaultContractResolver
                    {
                        NamingStrategy = new SnakeCaseNamingStrategy()
                    }
                });
                if (loadedBlockMap == null)
                {
                    Console.WriteLine("Invalid block map file, cancelling generation");
                    return;
                }

                blockMap = loadedBlockMap;
            }

            Console.WriteLine("Please enter the last version to support");
            if (!TryRequestVersionTag(api, out string?lastVersion))
            {
                Console.WriteLine("Cancelling generation");
                return;
            }



            //ILookup<ObjectId, Tag> commitToTag =
            //    repo.Tags
            //    .Select(t =>
            //        (
            //            tag: t,
            //            commit: t.PeeledTarget as Commit
            //        )
            //    )
            //    .Where(
            //        t => t.commit != null
            //    )
            //    .ToLookup(
            //        t => t.commit!.Id,
            //        t => t.tag
            //    );

            //IEnumerable<LogEntry> history = repo.Commits.QueryBy("generated/reports/blocks.json");
        }