Ну вот кажись и всё :) По крайней мере, я очёнь на это надеюсь!
This commit is contained in:
parent
d00e014de5
commit
f5635f97f4
@ -75,17 +75,19 @@ namespace TransportCompamyMongoDBImplementer.Implements
|
|||||||
//метод для замера вставки большого кол-ва клиентов в бд
|
//метод для замера вставки большого кол-ва клиентов в бд
|
||||||
public string TestRandomInsert(int count, string[] _name, string[] _surname, string[] _patronymic, string[] _telephone, string[] _email)
|
public string TestRandomInsert(int count, string[] _name, string[] _surname, string[] _patronymic, string[] _telephone, string[] _email)
|
||||||
{
|
{
|
||||||
/*using var context = new ElegevContext();
|
var clientCollection = context.ConnectToMongo<Client>("client");
|
||||||
|
|
||||||
Random rnd = new Random(DateTime.Now.ToString().GetHashCode());
|
Random rnd = new Random(DateTime.Now.ToString().GetHashCode());
|
||||||
|
|
||||||
int lastId = context.Clients.Count() > 0 ? context.Clients.Max(x => x.Id) + 1 : 1;
|
//старт замера времени добавления в бд
|
||||||
|
Stopwatch stopwatch = new();
|
||||||
|
|
||||||
|
stopwatch.Start();
|
||||||
|
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
var model = new Client
|
var model = new Client
|
||||||
{
|
{
|
||||||
Id = lastId,
|
|
||||||
Name = _name[rnd.Next(0, _name.Length)],
|
Name = _name[rnd.Next(0, _name.Length)],
|
||||||
Surname = _surname[rnd.Next(0, _surname.Length)],
|
Surname = _surname[rnd.Next(0, _surname.Length)],
|
||||||
Patronymic = _patronymic[rnd.Next(0, _patronymic.Length)],
|
Patronymic = _patronymic[rnd.Next(0, _patronymic.Length)],
|
||||||
@ -93,29 +95,19 @@ namespace TransportCompamyMongoDBImplementer.Implements
|
|||||||
Email = _email[rnd.Next(0, _email.Length)],
|
Email = _email[rnd.Next(0, _email.Length)],
|
||||||
};
|
};
|
||||||
|
|
||||||
lastId++;
|
clientCollection.InsertOne(model);
|
||||||
|
|
||||||
context.Clients.Add(model);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//старт замера времени добавления в бд
|
|
||||||
Stopwatch stopwatch = new();
|
|
||||||
|
|
||||||
stopwatch.Start();
|
|
||||||
|
|
||||||
context.SaveChanges();
|
|
||||||
|
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
|
|
||||||
return stopwatch.ElapsedMilliseconds.ToString();*/
|
return stopwatch.ElapsedMilliseconds.ToString();
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public string SecondJoin()
|
public string SecondJoin()
|
||||||
{
|
{
|
||||||
/*using var context = new ElegevContext();
|
var clientCollection = context.ConnectToMongo<Client>("client");
|
||||||
|
var truckingCollection = context.ConnectToMongo<Trucking>("trucking");
|
||||||
|
|
||||||
Random rnd = new Random(DateTime.Now.ToString().GetHashCode());
|
Random rnd = new Random(DateTime.Now.ToString().GetHashCode());
|
||||||
|
|
||||||
@ -124,34 +116,30 @@ namespace TransportCompamyMongoDBImplementer.Implements
|
|||||||
|
|
||||||
stopwatch.Start();
|
stopwatch.Start();
|
||||||
|
|
||||||
var secondJoin = from t in context.Set<Trucking>()
|
var secondJoin = from t in truckingCollection.Find(_ => true).ToList()
|
||||||
from c in context.Set<Client>().Where(c => c.Id == t.ClientId)
|
from c in clientCollection.Find(c => c.Id == t.Client.Id).ToList()
|
||||||
select new { c, t };
|
select new { c, t };
|
||||||
|
|
||||||
//ВСЁ ГОТОВО ДЛЯ СЛЕДУЮЩЕГО ЗАМЕРА
|
//ВСЁ ГОТОВО ДЛЯ СЛЕДУЮЩЕГО ЗАМЕРА
|
||||||
|
|
||||||
foreach (var element in secondJoin)
|
foreach (var element in secondJoin)
|
||||||
{
|
{
|
||||||
element.t.Update(new TruckingBindingModel
|
var trucking = truckingCollection.Find(x => x.Id == element.t.Id).FirstOrDefault();
|
||||||
{
|
|
||||||
Id = element.t.Id,
|
|
||||||
ClientId = element.t.ClientId,
|
|
||||||
CargoId = element.t.CargoId,
|
|
||||||
Price = element.t.Price,
|
|
||||||
DateStart = element.t.DateStart.AddDays(-10),
|
|
||||||
DateEnd = element.t.DateEnd.AddDays(-10),
|
|
||||||
TransportationId = element.t.TransportationId,
|
|
||||||
TransportId = element.t.TransportId,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
context.SaveChanges();
|
trucking.Update(new TruckingBindingModel
|
||||||
|
{
|
||||||
|
Price = element.t.Price,
|
||||||
|
DateStart = element.t.DateStart.AddDays(10),
|
||||||
|
DateEnd = element.t.DateEnd.AddDays(10)
|
||||||
|
});
|
||||||
|
|
||||||
|
var filter = Builders<Trucking>.Filter.Eq("Id", element.t.Id);
|
||||||
|
truckingCollection.ReplaceOne(filter, trucking, new ReplaceOptions { IsUpsert = true });
|
||||||
|
}
|
||||||
|
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
|
|
||||||
return stopwatch.ElapsedMilliseconds.ToString();*/
|
return stopwatch.ElapsedMilliseconds.ToString();
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClientViewModel? Update(ClientBindingModel model)
|
public ClientViewModel? Update(ClientBindingModel model)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using MongoDB.Driver;
|
using MongoDB.Driver;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Diagnostics.Contracts;
|
using System.Diagnostics.Contracts;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -35,7 +36,41 @@ namespace TransportCompamyMongoDBImplementer.Implements
|
|||||||
|
|
||||||
public string FirstJoin()
|
public string FirstJoin()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
var truckingCollection = context.ConnectToMongo<Trucking>("trucking");
|
||||||
|
var clientCollection = context.ConnectToMongo<Client>("client");
|
||||||
|
|
||||||
|
Random rnd = new Random(DateTime.Now.ToString().GetHashCode());
|
||||||
|
|
||||||
|
//старт замера времени добавления в бд
|
||||||
|
Stopwatch stopwatch = new();
|
||||||
|
|
||||||
|
stopwatch.Start();
|
||||||
|
|
||||||
|
var firstJoin = from t in truckingCollection.Find(t => t.Price == 999999.0).ToList()
|
||||||
|
from c in clientCollection.Find(c => c.Id == t.Client.Id).ToList()
|
||||||
|
select new { t, c };
|
||||||
|
|
||||||
|
//ВСЁ ГОТОВО ДЛЯ СЛЕДУЮЩЕГО ЗАМЕРА
|
||||||
|
// 999999.0
|
||||||
|
|
||||||
|
foreach (var element in firstJoin)
|
||||||
|
{
|
||||||
|
var trucking = truckingCollection.Find(x => x.Id == element.t.Id).FirstOrDefault();
|
||||||
|
|
||||||
|
trucking.Update(new TruckingBindingModel
|
||||||
|
{
|
||||||
|
Price = 1200000.0,
|
||||||
|
DateStart = element.t.DateStart,
|
||||||
|
DateEnd = element.t.DateEnd,
|
||||||
|
});
|
||||||
|
|
||||||
|
var filter = Builders<Trucking>.Filter.Eq("Id", element.t.Id);
|
||||||
|
truckingCollection.ReplaceOne(filter, trucking, new ReplaceOptions { IsUpsert = true });
|
||||||
|
}
|
||||||
|
|
||||||
|
stopwatch.Stop();
|
||||||
|
|
||||||
|
return stopwatch.ElapsedMilliseconds.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TruckingViewModel? GetElement(TruckingSearchModel model)
|
public TruckingViewModel? GetElement(TruckingSearchModel model)
|
||||||
@ -126,14 +161,61 @@ namespace TransportCompamyMongoDBImplementer.Implements
|
|||||||
|
|
||||||
public string TestGetFullList()
|
public string TestGetFullList()
|
||||||
{
|
{
|
||||||
//может и надо сделать
|
var truckingCollection = context.ConnectToMongo<Trucking>("trucking");
|
||||||
throw new NotImplementedException();
|
|
||||||
|
string result = null;
|
||||||
|
|
||||||
|
//для замера времени считывания из бд
|
||||||
|
Stopwatch stopwatch = new();
|
||||||
|
|
||||||
|
stopwatch.Start();
|
||||||
|
|
||||||
|
List<TruckingViewModel> list = truckingCollection.Find(_ => true)
|
||||||
|
.ToList()
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
stopwatch.Stop();
|
||||||
|
|
||||||
|
result = list.Count.ToString();
|
||||||
|
|
||||||
|
list.Clear();
|
||||||
|
|
||||||
|
return result + " " + stopwatch.ElapsedMilliseconds.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string TestRandomInsert(int count, List<ClientViewModel> clients, List<CargoViewModel> cargos, List<TransportViewModel> transports, List<TransportationViewModel> transportations)
|
public string TestRandomInsert(int count, List<ClientViewModel> clients, List<CargoViewModel> cargos, List<TransportViewModel> transports, List<TransportationViewModel> transportations)
|
||||||
{
|
{
|
||||||
//может и надо сделать
|
var truckingCollection = context.ConnectToMongo<Trucking>("trucking");
|
||||||
throw new NotImplementedException();
|
|
||||||
|
Random rnd = new Random(DateTime.Now.ToString().GetHashCode());
|
||||||
|
|
||||||
|
//старт замера времени добавления в бд
|
||||||
|
Stopwatch stopwatch = new();
|
||||||
|
|
||||||
|
stopwatch.Start();
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
DateTime dateStart = new(rnd.Next(1991, 2023), rnd.Next(1, 12), rnd.Next(1, 28));
|
||||||
|
DateTime dateEnd = dateStart.AddDays(20);
|
||||||
|
|
||||||
|
var model = Trucking.Create(context, new()
|
||||||
|
{
|
||||||
|
Client = clients[rnd.Next(0, clients.Count)].MongoId,
|
||||||
|
Cargo = cargos[rnd.Next(0, cargos.Count)].MongoId,
|
||||||
|
Transport = transports[rnd.Next(0, transports.Count)].MongoId,
|
||||||
|
DateStart = dateStart,
|
||||||
|
DateEnd = dateEnd,
|
||||||
|
Price = clients.Count * rnd.Next(100, 5000)
|
||||||
|
});
|
||||||
|
|
||||||
|
truckingCollection.InsertOne(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
stopwatch.Stop();
|
||||||
|
|
||||||
|
return stopwatch.ElapsedMilliseconds.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TruckingViewModel? Update(TruckingBindingModel model)
|
public TruckingViewModel? Update(TruckingBindingModel model)
|
||||||
|
@ -36,7 +36,7 @@ namespace TransportCompany
|
|||||||
|
|
||||||
private void ButtonStartTransfer_Click(object sender, EventArgs e)
|
private void ButtonStartTransfer_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var soundPlayer = new SoundPlayer(@"C:\Users\Programmist73\Desktop\Практика\2-й курс\4-й семестр\СУБД\Лаб. раб. №8\uda_requie.wav");
|
var soundPlayer = new SoundPlayer(@"C:\Users\Programmist73\Desktop\Практика\2-й курс\4-й семестр\СУБД\Лаб. раб. №8\led-tronulsya.wav");
|
||||||
|
|
||||||
soundPlayer.PlaySync(); // can also use soundPlayer.PlaySync()
|
soundPlayer.PlaySync(); // can also use soundPlayer.PlaySync()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user