private void loaddb() { if (!firstrun) { fstrun(); } if (database.Count != 0) { return; } conn.Open(); string sql = "SELECT name, x, y, z FROM systems where action_todo = 1 and deleted_at is NULL;"; NpgsqlTransaction tran = conn.BeginTransaction(); NpgsqlCommand command = new NpgsqlCommand(sql, conn); NpgsqlDataReader read = command.ExecuteReader(); while (read.Read()) { star_st ret = new star_st(); ret.name = read["name"].ToString(); ret.coord.x = Double.Parse(read["x"].ToString(), CultureInfo.InvariantCulture); ret.coord.y = Double.Parse(read["y"].ToString(), CultureInfo.InvariantCulture); ret.coord.z = Double.Parse(read["z"].ToString(), CultureInfo.InvariantCulture); database.Add(ret); } conn.Close(); }
public star_st zen(star_st start, int distance = 18000) { fstrun(); loaddb(); star_st saga = new star_st(); saga.name = "Sagittarius A*"; saga.coord.x = 25.21875; saga.coord.y = -20.90625; saga.coord.z = 25899.96875; List <star_st> list = new List <star_st>(); foreach (star_st x in database) { if (x.distance(start) > distance && x.distance(start) < 20000) { list.Add(x); } } if (list.Count > 0) { int rand = rnd.Next(0, list.Count); star_st ret = list[rand]; list.Remove(ret); return(ret); } return(saga); }
private void Form1_Load(object sender, EventArgs e) { curr = searchbyname("sol"); textBox1.Text = "Enter Cmdr Name"; button1.Enabled = false; button2.Enabled = false; toolStripLabel1.Text = ""; }
private void button1_Click(object sender, EventArgs e) { string result = new System.Net.WebClient().DownloadString("https://www.edsm.net/api-logs-v1/get-position?commanderName=" + textBox1.Text); curr = searchbyname(result.Substring(result.IndexOf(",\"system\":\"") + ",\"system\":\"".Length, result.IndexOf("\",\"firstDiscover") - (result.IndexOf(",\"system\":\"") + ",\"system\":\"".Length))); textBox2.Text = curr.name + Environment.NewLine + curr.value; button2.Text = "Open " + curr.name; button2.Enabled = true; }
public double angle(star_st other, star_st reference) { dist_block_st distblk = new dist_block_st(); distblk.c = this.distance(reference); distblk.b = this.distance(other); distblk.a = other.distance(reference); return(Math.Acos((Math.Pow(distblk.a, 2) - Math.Pow(distblk.b, 2) - Math.Pow(distblk.c, 2)) / ((-2) * distblk.b * distblk.c)) * (180 / Math.PI));//(a^2-b^2-c^2)/2bc }
public star_st searchbyname(string starname) { string result = new System.Net.WebClient().DownloadString("https://www.edsm.net/api-system-v1/estimated-value?systemName=" + starname); star_st ret = new star_st(); ret.name = starname; if (result.IndexOf(",\"estimatedValue\":") == -1) { ret.value = -1; ret.url = ""; return(ret); } ret.value = Int64.Parse(result.Substring(result.IndexOf(",\"estimatedValue\":") + ",\"estimatedValue\":".Length, result.Length - (result.IndexOf(",\"estimatedValue\":") + ",\"estimatedValue\":".Length) - 1)); ret.url = result.Substring(result.IndexOf(",\"url\":") + ",\"url\":".Length, (result.IndexOf(",\"estimatedValue\":") - (result.IndexOf(",\"url\":") + ",\"url\":".Length))).Replace("\\", ""); ret.url = ret.url.Substring(1, ret.url.Length - 2); return(ret); }
private bool checkstar(star_st check) { if (lastchecked < DateTime.Now.AddSeconds(1)) { lastchecked = DateTime.Now; numofchecks = 0; } numofchecks++; if (numofchecks < 6) { string result = new System.Net.WebClient().DownloadString("https://www.edsm.net/api-v1/systems?systemName=" + check.name + "&showCoordinates=1"); if (!(result == "[]" || !result.Contains("coords"))) { return(false); } } return(false); }
public star_st searchbyname(string starname) { string result = new System.Net.WebClient().DownloadString("https://www.edsm.net/api-v1/systems?systemName=" + HttpUtility.UrlEncode(starname) + "&showCoordinates=1"); if (result == "[]") { return(new star_st()); } if (!result.Contains("coords")) { return(new star_st()); } star_st ret = new star_st(); ret.name = starname; ret.coord.x = Double.Parse((result.Substring(result.IndexOf("\"x\":") + "\"x\":".Length, result.IndexOf(",\"y\":") - (result.IndexOf("\"x\":") + "\"x\":".Length))), CultureInfo.InvariantCulture); ret.coord.y = Double.Parse((result.Substring(result.IndexOf(",\"y\":") + ",\"y\":".Length, result.IndexOf(",\"z\":") - (result.IndexOf(",\"y\":") + ",\"y\":".Length))), CultureInfo.InvariantCulture); ret.coord.z = Double.Parse((result.Substring(result.IndexOf(",\"z\":") + ",\"z\":".Length, result.IndexOf("}") - (result.IndexOf(",\"z\":") + ",\"z\":".Length))), CultureInfo.InvariantCulture); numofchecks++; return(ret); }
public double distance(star_st other) { return(Math.Sqrt(Math.Pow(this.coord.x - other.coord.x, 2) + Math.Pow(this.coord.y - other.coord.y, 2) + Math.Pow(this.coord.z - other.coord.z, 2))); }
public star_st findnext(star_st curr, star_st dest, int variation = 20, int min_dist = 0) { fstrun(); div_st div = new div_st(); div_st dir = new div_st(); div.x = dest.coord.x - curr.coord.x; div.y = dest.coord.y - curr.coord.y; div.z = dest.coord.z - curr.coord.z; dir.x = div.x >= 0 ? 1 : -1; dir.y = div.y >= 0 ? 1 : -1; dir.z = div.z >= 0 ? 1 : -1; double dist = curr.distance(dest); double jumps = dist / 1000; if (dist < min_dist) { return(dest); } coord_block_st query = new coord_block_st(); query.x_start = curr.coord.x + (div.x / jumps) + (dir.x * min_dist / 3) - 1000; query.x_end = curr.coord.x + (div.x / jumps) + (dir.x * min_dist / 3) + 1000; query.y_start = curr.coord.y + (div.y / jumps) - 200; query.y_end = curr.coord.y + (div.y / jumps) + 200; query.z_start = curr.coord.z + (div.z / jumps) + (dir.z * min_dist / 3) - 1000; query.z_end = curr.coord.z + (div.z / jumps) + (dir.z * min_dist / 3) + 1000; conn.Open(); string sql = "SELECT name, x, y, z FROM systems where x BETWEEN " + query.x_start.ToString(CultureInfo.InvariantCulture) + " and " + query.x_end.ToString(CultureInfo.InvariantCulture) + " and y BETWEEN " + query.y_start.ToString(CultureInfo.InvariantCulture) + " and " + query.y_end.ToString(CultureInfo.InvariantCulture) + " and z BETWEEN " + query.z_start.ToString(CultureInfo.InvariantCulture) + " and " + query.z_end.ToString(CultureInfo.InvariantCulture) + " and action_todo = 1 and deleted_at is NULL;"; NpgsqlCommand command = new NpgsqlCommand(sql, conn); NpgsqlDataReader read = command.ExecuteReader(); List <check_st> collect = new List <check_st>(); while (read.Read()) { check_st ret = new check_st(); ret.star.name = read["name"].ToString(); ret.star.coord.x = Double.Parse(read["x"].ToString(), CultureInfo.InvariantCulture); ret.star.coord.y = Double.Parse(read["y"].ToString(), CultureInfo.InvariantCulture); ret.star.coord.z = Double.Parse(read["z"].ToString(), CultureInfo.InvariantCulture); ret.dist = ret.star.distance(curr); ret.angle = curr.angle(ret.star, dest); collect.Add(ret); } conn.Close(); check_st temp = new check_st(); temp.star = dest; temp.dist = dist; temp.angle = 0; collect.Add(temp); collect.Sort(); for (int x = 0; x != collect.Count; x++) { if (collect[x].angle < variation)// || (collect[x].dist == 0 && collect[x].star.name != curr.name)) { if (collect[x].dist > min_dist) { //if (checkstar(collect[x].star)) return(collect[x].star); } } } return(dest);//This will never be reached, but just in case }
public static user_st work(user_st user) { Random r = new Random(user.jumprange + (int)user.lastjump.Ticks); DateTime timetogglestart = DateTime.Now; while (jumptoggle?user.jumpnum != maxjumpnum:timetogglestart.AddMinutes(totalminutes) > DateTime.Now) { if (user.lastjump.Add(user.next_query_time) < DateTime.Now) { //Adjust position if (r.Next(0, 3) > 1) { user.x = user.x + user.jumprange; } else { user.x = user.x - user.jumprange; } if (r.Next(0, 3) > 1) { user.z = user.z + user.jumprange; } else { user.z = user.z - user.jumprange; } user.lastjump = DateTime.Now; //create location for mathmatics star_st curr = new star_st(); curr.coord.x = user.x; curr.coord.y = user.y; curr.coord.z = user.z; //query history_st next = new history_st(); next.radius = queryRadius[user.query]; DateTime start = DateTime.Now; next.query = "SELECT * FROM systems WHERE " + "systems.x BETWEEN " + (user.x - queryRadius[user.query]) + " AND " + (user.x + queryRadius[user.query]) + " AND " + "systems.y BETWEEN " + (user.y - queryRadius[user.query]) + " AND " + (user.y + queryRadius[user.query]) + " AND " + "systems.z BETWEEN " + (user.z - queryRadius[user.query]) + " AND " + (user.z + queryRadius[user.query] + " AND deleted_at is NULL;"); try { NpgsqlConnection conn = new NpgsqlConnection("Pooling=false; SERVER=cyberlord.de; Port=5432; Database=edmc_rse_db; User ID=edmc_rse_user; Password=asdfplkjiouw3875948zksmdxnf;Timeout=12;Application Name=stresstest-" + user.name); conn.Open(); NpgsqlTransaction tran = conn.BeginTransaction(); NpgsqlCommand command = new NpgsqlCommand(next.query, conn); NpgsqlDataReader read = command.ExecuteReader(); while (read.Read()) { check_st ret = new check_st(); ret.star.name = read["name"].ToString(); ret.star.coord.x = Double.Parse(read["x"].ToString(), CultureInfo.InvariantCulture); ret.star.coord.y = Double.Parse(read["y"].ToString(), CultureInfo.InvariantCulture); ret.star.coord.z = Double.Parse(read["z"].ToString(), CultureInfo.InvariantCulture); ret.dist = ret.star.distance(curr); next.resultnum++; } //cleanup, prep next jump conn.Close(); next.error_bool = false; } catch (Exception e) { next.resultnum = -1; next.error_bool = true; next.error_string = e.Message; } next.time = DateTime.Now - start; next.jumpnum = user.jumpnum; user.history.Add(next); if (user.history[user.jumpnum].resultnum < 15 && user.query < 10) { user.query++; } else if (user.history[user.jumpnum].resultnum > 100 && user.query > 0) { user.query--; } user.jumpnum++; } else { Thread.Sleep(((user.lastjump.Add(user.next_query_time) - DateTime.Now).TotalSeconds > new TimeSpan(0, 0, 2).TotalSeconds ? (user.lastjump.Add(user.next_query_time) - DateTime.Now) : new TimeSpan(1))); } } return(user); }
public star_st findnext(star_st curr, star_st dest, int variation = 20, int min_dist = 0) { fstrun(); double dist = curr.distance(dest); double dev = dist / 3; coord_block_st query = new coord_block_st(); query.x_start = curr.coord.x > dest.coord.x ? dest.coord.x - dev : curr.coord.x - dev; query.x_end = curr.coord.x < dest.coord.x ? dest.coord.x + dev : curr.coord.x + dev; query.y_start = curr.coord.y > dest.coord.y ? dest.coord.y - dev : curr.coord.y - dev; query.y_end = curr.coord.y < dest.coord.y ? dest.coord.y + dev : curr.coord.y + dev; query.z_start = curr.coord.z > dest.coord.z ? dest.coord.z - dev : curr.coord.z - dev; query.z_end = curr.coord.z < dest.coord.z ? dest.coord.z + dev : curr.coord.z + dev; conn.Open(); string sql = "SELECT name, x, y, z FROM systems where x BETWEEN " + query.x_start.ToString(CultureInfo.InvariantCulture) + " and " + query.x_end.ToString(CultureInfo.InvariantCulture) + " and y BETWEEN " + query.y_start.ToString(CultureInfo.InvariantCulture) + " and " + query.y_end.ToString(CultureInfo.InvariantCulture) + " and z BETWEEN " + query.z_start.ToString(CultureInfo.InvariantCulture) + " and " + query.z_end.ToString(CultureInfo.InvariantCulture) + " and action_todo = 1 and deleted_at is NULL;"; //Console.WriteLine(curr.name + "|" + curr.coord.x+"|" + curr.coord.y+ "|" + curr.coord.z); //Console.WriteLine(dest.name + "|" + dest.coord.x + "|" + dest.coord.y + "|" + dest.coord.z); //Console.WriteLine(variation); //Console.WriteLine(min_dist); //Console.WriteLine(sql); NpgsqlTransaction tran = conn.BeginTransaction(); NpgsqlCommand command = new NpgsqlCommand(sql, conn); NpgsqlDataReader read = command.ExecuteReader(); List <check_st> collect = new List <check_st>(); while (read.Read()) { check_st ret = new check_st(); ret.star.name = read["name"].ToString(); ret.star.coord.x = Double.Parse(read["x"].ToString(), CultureInfo.InvariantCulture); ret.star.coord.y = Double.Parse(read["y"].ToString(), CultureInfo.InvariantCulture); ret.star.coord.z = Double.Parse(read["z"].ToString(), CultureInfo.InvariantCulture); ret.dist = ret.star.distance(curr); ret.angle = curr.angle(ret.star, dest); collect.Add(ret); } conn.Close(); check_st temp = new check_st(); temp.star = dest; temp.dist = dist; temp.angle = 0; collect.Add(temp); collect.Sort(); for (int x = 0; x != collect.Count; x++) { if (collect[x].angle < variation)// || (collect[x].dist == 0 && collect[x].star.name != curr.name)) { if (collect[x].dist > min_dist) { //if (checkstar(collect[x].star)) return(collect[x].star); } } } return(dest);//This will never be reached, but just in case }