2using System.Collections.Generic;
9using System.Runtime.InteropServices;
13using System.Data.Entity.Infrastructure;
15using System.Threading.Tasks;
29 List<Label> m_rgLabelCache;
46 object m_objSync =
new object();
47 Dictionary<int, string> m_rgSecondarySourcePath =
new Dictionary<int, string>();
48 object m_objRawImgSync =
new object();
49 Dictionary<string, string> m_rgstrDatabaseFilePath =
new Dictionary<string, string>();
50 object m_objRemoteSync =
new object();
51 FileWriter m_fileWriter =
null;
84 if (m_fileWriter !=
null)
85 m_fileWriter.Cancel();
104 List<RawImage> rgImg = entities.RawImages.Where(p => p.SourceID == nSrcId).Take(1).ToList();
105 if (rgImg.Count == 0)
106 throw new Exception(
"No images found for data source = '" + strSrc +
"' on connection: " + ci.
ToString(
"signalpop."));
108 byte[] rgRawData = rgImg[0].Data;
109 int nVirtualId = rgImg[0].VirtualID.GetValueOrDefault(0);
110 if (rgRawData ==
null && nVirtualId > 0)
112 int nSrcId1 = rgImg[0].OriginalSourceID.GetValueOrDefault(rgImg[0].SourceID.GetValueOrDefault(0));
113 rgImg = entities.RawImages.Where(p => p.ID == nVirtualId).Take(1).ToList();
114 if (rgImg.Count == 0)
115 throw new Exception(
"No images found for data source = '" + strSrc +
"' on connection: " + ci.
ToString(
"signalpop."));
117 rgRawData = rgImg[0].Data;
122 byte[] rgData =
getRawImage(rgRawData,
null, ci, entities,
true);
123 if (rgData ==
null || rgData.Length == 0)
124 throw new Exception(
"The image at image ID = " + rgImg[0].ID.ToString() +
" for data source = '" + strSrc +
"' on connection: " + ci.
ToString(
"signalpop.") +
" is empty!");
126 catch (Exception excpt)
128 throw new Exception(
"Failed to get raw image data for data source = '" + strSrc +
"' on connection: " + ci.
ToString(
"signalpop.") +
" with error = '" + excpt.Message +
"'", excpt);
147 private string convertWs(
string str,
char chReplacement)
154 foreach (
char ch
in str)
156 if (
char.IsWhiteSpace(ch))
157 strOut += chReplacement;
170 if (m_entities !=
null)
171 m_entities.SaveChanges();
179 get {
return m_src; }
192 throw new Exception(
"Could not find the source with ID = " + nSrcId.ToString());
195 m_rgLabelCache = loadLabelCache(
m_src.ID);
211 public void Open(
string strSrc,
bool bForceLoadImageFilePath =
false)
215 m_rgLabelCache = loadLabelCache(
m_src.ID);
234 if (
m_src.SaveImagesToFile.GetValueOrDefault(
false) || nForceLoad ==
FORCE_LOAD.FROM_FILE)
252 return getImagePathBase(strSrcName);
255 string getImagePathBase(
string strSrcName =
null,
DNNEntities entities =
null)
257 if (strSrcName ==
null)
262 strSrcName =
m_src.Name;
264 if (
m_src.CopyOfSourceID > 0)
268 if (entities ==
null)
269 entities = m_entities;
281 if (m_entities !=
null)
283 m_entities.Dispose();
296 int nSrcId =
m_src.ID;
311 if (m_rgstrDatabaseFilePath.ContainsKey(strName))
312 return m_rgstrDatabaseFilePath[strName];
316 string strCmd =
"SELECT physical_name FROM sys.master_files WHERE name = '" + strName +
"'";
317 DbRawSqlQuery<string> qry = entities.Database.SqlQuery<
string>(strCmd);
318 List<string> rgStr = qry.ToList();
320 if (rgStr.Count == 0)
323 FileInfo fi =
new FileInfo(rgStr[0]);
324 string strDir = fi.DirectoryName;
326 string strPath = strDir +
"\\";
328 m_rgstrDatabaseFilePath.Add(strName, strPath);
342 string strPath = strDir +
"Images\\" + strName +
"\\";
352 private List<Label> loadLabelCache(
int nSrcId)
354 return m_entities.Labels.Where(p => p.SourceID == nSrcId).ToList();
370 List<Label> rg = entities.Labels.Where(p => p.SourceID == nSrcId && p.ActiveLabel == nLabel).ToList();
377 l.ActiveLabel = nLabel;
381 entities.Labels.Add(l);
390 entities.SaveChanges();
401 foreach (Label l
in m_rgLabelCache)
420 foreach (Label l
in m_rgLabelCache)
422 if (l.Label1 == nLabel)
432 List<Label> rg = entities.Labels.AsNoTracking().Where(p => p.SourceID == nSrcId && p.Label1 == nLabel).ToList();
449 foreach (Label l
in m_rgLabelCache)
451 if (l.ActiveLabel == nLabel)
465 foreach (Label l
in m_rgLabelCache)
467 if (l.ActiveLabel == nLabel)
481 foreach (Label l
in m_rgLabelCache)
483 if (l.ActiveLabel == nLabel)
484 return l.ImageCount.GetValueOrDefault(0);
503 l.SourceID =
m_src.ID;
505 l.ActiveLabel = nLabel;
506 m_rgLabelCache.Add(l);
521 foreach (Label l
in m_rgLabelCache)
523 List<Label> rgLabels = entities.Labels.Where(p => p.SourceID ==
m_src.ID && p.Label1 == l.Label1).ToList();
525 if (rgLabels.Count == 0)
527 if (!l.ActiveLabel.HasValue)
528 l.ActiveLabel = l.Label1;
530 entities.Labels.Add(l);
534 entities.SaveChanges();
545 if (entities ==
null)
546 entities = m_entities;
548 foreach (Label l
in m_rgLabelCache)
553 foreach (KeyValuePair<int, int> kv
in rgCounts)
555 List<Label> rgLabel = m_rgLabelCache.Where(p => p.ActiveLabel == kv.Key).ToList();
557 if (rgLabel.Count > 0)
558 rgLabel[0].ImageCount = kv.Value;
561 entities.SaveChanges();
576 List<Label> rgLabels = entities.Labels.AsNoTracking().Where(p => p.SourceID == nSrcId).ToList();
578 foreach (Label l
in rgLabels)
580 int nCount = entities.RawImages.Where(p => p.SourceID == nSrcId && p.ActiveLabel == l.ActiveLabel && p.Active ==
true).Count();
581 rgCounts.Add(l.ActiveLabel.GetValueOrDefault(), nCount);
600 if (ci.Location ==
ConnectInfo.
TYPE.AZURE || !
string.IsNullOrEmpty(ci.Password))
605 List<Label> rgLabels = entities.Labels.AsNoTracking().Where(p => p.SourceID == nSrcId).OrderBy(p => p.Label1).ToList();
607 string strOut =
"(" + rgLabels.Count.ToString() +
") {";
609 foreach (Label l
in rgLabels)
611 strOut += l.ImageCount.GetValueOrDefault().ToString();
615 strOut = strOut.TrimEnd(
',');
634 List<Label> rgLabels = entities.Labels.Where(p => p.SourceID == nSrcId).ToList();
636 foreach (Label l
in rgLabels)
641 foreach (KeyValuePair<int, int> kv
in rgCounts)
643 List<Label> rgLabel = rgLabels.Where(p => p.ActiveLabel == kv.Key).ToList();
645 if (rgLabel.Count > 0)
646 rgLabel[0].ImageCount = kv.Value;
649 entities.SaveChanges();
661 Dictionary<int, double> rgLabelBoosts =
null;
668 rgLabelBoosts =
new Dictionary<int, double>();
672 List<Label> rgLabels = entities.Labels.Where(p => p.SourceID == nSrcId).ToList();
674 foreach (Label l
in rgLabels)
676 int nCount = entities.RawImages.Where(p => p.SourceID == nSrcId && p.ActiveLabel == l.ActiveLabel && p.Active ==
true).Count();
677 l.ImageCount = nCount;
681 rgLabelBoosts.Add(l.ActiveLabel.GetValueOrDefault(0), nCount);
686 entities.SaveChanges();
692 throw new Exception(
"There are no images for label boost!");
694 foreach (
int nKey
in rgLabelBoosts.Keys)
696 AddLabelBoost(nProjectId, nKey, rgLabelBoosts[nKey] / dfTotal, nSrcId);
710 public List<Label>
GetLabels(
bool bSort =
true,
bool bWithImagesOnly =
false,
int nSrcId = 0,
ConnectInfo ci =
null)
717 List<Label> rgLabels = entities.Labels.AsNoTracking().Where(p => p.SourceID == nSrcId).ToList();
720 rgLabels = rgLabels.Where(p => p.ImageCount > 0).ToList();
723 rgLabels = rgLabels.OrderBy(p => p.Label1).ToList();
740 string strCmd =
"DELETE FROM [DNN].[dbo].[Labels] WHERE (SourceID = " + nSrcId.ToString() +
")";
741 entities.Database.ExecuteSqlCommand(strCmd);
760 List<Label> rgLabel = entities.Labels.Where(p => p.SourceID == nSrcId && p.Label1 == nLabel).ToList();
763 if (rgLabel.Count > 0)
774 l.ActiveLabel = nLabel;
778 if (rgLabel.Count == 0)
779 entities.Labels.Add(l);
781 entities.SaveChanges();
794 public void AddLabelBoost(
int nProjectId,
int nLabel,
double dfBoost,
int nSrcId = 0)
801 List<LabelBoost> rgLabelBoosts = entities.LabelBoosts.Where(p => p.ProjectID == nProjectId && p.SourceID == nSrcId && p.ActiveLabel == nLabel).ToList();
804 if (rgLabelBoosts.Count > 0)
806 lb = rgLabelBoosts[0];
810 lb =
new LabelBoost();
811 lb.ActiveLabel = nLabel;
812 lb.ProjectID = nProjectId;
813 lb.SourceID = nSrcId;
816 lb.Boost = (decimal)dfBoost;
818 if (rgLabelBoosts.Count == 0)
819 entities.LabelBoosts.Add(lb);
821 entities.SaveChanges();
837 entities.Database.CommandTimeout = 180;
838 string strCmd =
"UPDATE [DNN].[dbo].[RawImages] SET [ActiveLabel] = " + map.
NewLabel.ToString() +
" WHERE (SourceID = " + nSrcId.ToString() +
")";
839 strCmd +=
" AND (OriginalLabel = " + map.
OriginalLabel.ToString() +
")";
844 entities.Database.ExecuteSqlCommand(strCmd);
850 strCmd =
"UPDATE [DNN].[dbo].[RawImages] SET [ActiveLabel] = " + map.
NewLabelConditionFalse.Value.ToString() +
" WHERE (SourceID = " + nSrcId.ToString() +
")";
852 strCmd +=
" AND (OriginalLabel = " + map.
OriginalLabel.ToString() +
")";
854 entities.Database.ExecuteSqlCommand(strCmd);
873 string strCmd =
"UPDATE [DNN].[dbo].[RawImages] SET [ActiveLabel] = " + nNewLabel.ToString() +
" WHERE (SourceID = " + nSrcId.ToString() +
") AND (";
875 for (
int i = 0; i < rgOriginalLabels.Count; i++)
877 strCmd +=
"OriginalLabel = " + rgOriginalLabels[i].ToString();
879 if (i < rgOriginalLabels.Count - 1)
885 entities.Database.ExecuteSqlCommand(strCmd);
901 entities.Database.CommandTimeout = 180;
903 string strResetCmd =
"UPDATE [DNN].[dbo].[RawImages] SET [ActiveLabel] = [OriginalLabel] WHERE (SourceID = " + nSrcId.ToString() +
")";
904 entities.Database.ExecuteSqlCommand(strResetCmd);
923 string strCmd =
"DELETE FROM [DNN].[dbo].[LabelBoosts] WHERE (ProjectID = " + nProjectId.ToString() +
") AND (SourceID = " + nSrcId.ToString() +
")";
924 entities.Database.ExecuteSqlCommand(strCmd);
936 string strCmd =
"DELETE FROM [DNN].[dbo].[LabelBoosts] WHERE (ProjectID = " + nProjectId.ToString() +
")";
937 entities.Database.ExecuteSqlCommand(strCmd);
949 List<LabelBoost> rgLabels = entities.LabelBoosts.Where(p => p.ProjectID == nProjectId).ToList();
951 foreach (LabelBoost l
in rgLabels)
956 entities.SaveChanges();
967 public List<LabelBoost>
GetLabelBoosts(
int nProjectId,
bool bSort =
true,
int nSrcId = 0)
974 List<LabelBoost> rgBoosts = entities.LabelBoosts.AsNoTracking().Where(p => p.ProjectID == nProjectId && p.SourceID == nSrcId).ToList();
977 rgBoosts = rgBoosts.OrderBy(p => p.ActiveLabel).ToList();
995 List<LabelBoost> rgLb =
GetLabelBoosts(nProjectId, bSort, nSrcId);
998 foreach (LabelBoost lb
in rgLb)
1000 strOut += lb.Boost.GetValueOrDefault().ToString(
"N2");
1004 return strOut.TrimEnd(
',');
1015 string strSQL =
"UPDATE [dbo].[RawImages] SET [Active] = " + ((bActive) ?
"1" :
"0") +
" WHERE (";
1017 for (
int i = 0; i < rgSrcId.Length; i++)
1019 strSQL +=
"(SourceID = " + rgSrcId[i].ToString() +
")";
1021 if (i < rgSrcId.Length - 1)
1025 strSQL +=
") AND (";
1027 for (
int i = 0; i < rgLabels.Count; i++)
1029 strSQL +=
"(ActiveLabel = " + rgLabels[i].ToString() +
")";
1031 if (i < rgLabels.Count - 1)
1039 entities.Database.ExecuteSqlCommand(strSQL);
1053 public void UpdateLabelBoost(
int? nTgtLbl,
bool bTgtLblExact,
int? nTgtBst,
bool bTgtBstExact,
int? nNewLbl,
int? nNewBst, params
int[] rgSrcId)
1055 if (rgSrcId.Length == 0)
1056 throw new Exception(
"You must specify at least one source ID!");
1058 string strSQL =
"UPDATE [dbo].[RawImages] SET [Active] = 1";
1060 if (nNewLbl.HasValue)
1061 strSQL +=
", [ActiveLabel] = " + nNewLbl.Value.ToString();
1063 if (nNewBst.HasValue)
1064 strSQL +=
", [ActiveBoost] = " + nNewBst.Value.ToString();
1066 strSQL +=
" WHERE (";
1068 for (
int i = 0; i < rgSrcId.Length; i++)
1070 strSQL +=
"([SourceID] = " + rgSrcId[i].ToString() +
")";
1072 if (i < rgSrcId.Length - 1)
1076 if (nTgtBst.HasValue || nTgtLbl.HasValue)
1077 strSQL +=
") AND (";
1079 if (nTgtLbl.HasValue)
1082 strSQL +=
"[ActiveLabel] ";
1083 strSQL += (bTgtLblExact) ?
"=" :
">=";
1084 strSQL += nTgtLbl.Value.ToString();
1088 if (nTgtBst.HasValue)
1090 if (nTgtLbl.HasValue)
1094 strSQL +=
"[ActiveBoost] ";
1095 strSQL += (bTgtBstExact) ?
"=" :
">=";
1096 strSQL += nTgtBst.Value.ToString();
1104 entities.Database.ExecuteSqlCommand(strSQL);
1122 return m_entities.RawImages.AsNoTracking().Where(p => p.SourceID ==
m_src.ID).Count();
1136 int nSrcID =
m_src.ID;
1137 IQueryable<RawImage> iQuery = entities.RawImages.AsNoTracking().Where(p => p.SourceID == nSrcID);
1139 if (bIncludeActive && !bIncludeInactive)
1140 iQuery = iQuery.Where(p => p.Active ==
true);
1141 else if (!bIncludeActive && bIncludeInactive)
1142 iQuery = iQuery.Where(p => p.Active ==
false);
1145 iQuery = iQuery.Where(p => p.ActiveBoost > 0);
1147 iQuery = iQuery.OrderBy(p => p.Idx);
1149 return iQuery.Select(p =>
new DbItem {
id = p.
ID, virtualid = p.VirtualID, index = p.Idx, label = p.ActiveLabel, boost = p.ActiveBoost, time = p.TimeStamp, desc = p.Description, originalsrcid = p.OriginalSourceID, active = p.Active }).ToList();
1162 List<int?> rgSrcId1 =
new List<int?>();
1164 foreach (
int id in rgSrcId)
1169 return entities.RawImages.AsNoTracking().Where(p => rgSrcId1.Contains(p.SourceID)).ToList();
1183 IQueryable<RawImageParameter> iQuery = entities.RawImageParameters.AsNoTracking().Where(p => p.SourceID == nSrcId && p.Name == strName);
1184 return iQuery.ToList();
1197 IQueryable<RawImageParameter> iQuery = entities.RawImageParameters.AsNoTracking().Where(p => p.RawImageID == nImageID);
1198 return iQuery.ToList();
1211 public List<RawImage>
QueryRawImages(
int nSrcId,
bool? bActive =
null,
int nBoostVal = 0,
bool bExactBoostVal =
false)
1215 IQueryable<RawImage> iQuery = entities.RawImages.AsNoTracking().Where(p => p.SourceID == nSrcId);
1217 if (bActive.HasValue)
1219 bool bVal = bActive.Value;
1220 iQuery = iQuery.Where(p => p.Active == bVal);
1226 iQuery = iQuery.Where(p => p.ActiveBoost == nBoostVal);
1228 iQuery = iQuery.Where(p => p.ActiveBoost >= nBoostVal);
1231 return iQuery.ToList();
1243 public List<RawImage>
GetRawImagesAt(
int nIdx,
int nCount,
int nSrcId = 0,
string strDescription =
null)
1248 string strCmd =
"SELECT TOP " + nCount.ToString() +
" * FROM [DNN].[dbo].[RawImages] WHERE (SourceID = " + nSrcId.ToString() +
") AND (Idx >= " + nIdx.ToString() +
") AND (Active = 1)";
1250 if (!String.IsNullOrEmpty(strDescription))
1251 strCmd +=
" AND (Description = " + strDescription +
")";
1253 strCmd +=
" ORDER BY Idx";
1255 return m_entities.Database.SqlQuery<RawImage>(strCmd).ToList();
1265 public List<RawImage>
GetRawImagesAt(List<int> rgImageIdx,
int nSrcId = 0,
string strDescription =
null)
1270 if (rgImageIdx.Count > 100)
1271 throw new Exception(
"You can only query up to 100 images at a time when using the list of image indexes.");
1273 string strCmd =
"SELECT * FROM [DNN].[dbo].[RawImages] WHERE (SourceID = " + nSrcId.ToString() +
") AND (";
1275 for (
int i = 0; i < rgImageIdx.Count; i++)
1277 strCmd +=
"Idx = " + rgImageIdx[i].ToString();
1279 if (i < rgImageIdx.Count-1)
1283 strCmd +=
") AND (Active = 1)";
1285 if (!String.IsNullOrEmpty(strDescription))
1286 strCmd +=
" AND (Description = " + strDescription +
")";
1288 return m_entities.Database.SqlQuery<RawImage>(strCmd).ToList();
1299 public List<RawImage>
GetRawImagesAtID(List<int> rgImageID,
int nSrcId = 0,
string strDescription =
null)
1304 if (rgImageID.Count > 100)
1305 throw new Exception(
"You can only query up to 100 images at a time when using the list of image indexes.");
1307 string strCmd =
"SELECT * FROM [DNN].[dbo].[RawImages] WHERE (SourceID = " + nSrcId.ToString() +
") AND (";
1309 for (
int i = 0; i < rgImageID.Count; i++)
1311 strCmd +=
"ID = " + rgImageID[i].ToString();
1313 if (i < rgImageID.Count - 1)
1317 strCmd +=
") AND (Active = 1)";
1319 if (!String.IsNullOrEmpty(strDescription))
1320 strCmd +=
" AND (Description = " + strDescription +
")";
1322 lock (m_objRemoteSync)
1324 return m_entities.Database.SqlQuery<RawImage>(strCmd).ToList();
1339 string strCmd =
"SELECT TOP 1 * FROM [DNN].[dbo].[RawImages] WHERE (SourceID = " + nSrcId.ToString() +
") AND (Idx = " + nIdx.ToString() +
") AND (Active = 1)";
1340 List<RawImage> rgImg =
null;
1344 rgImg = m_entities.Database.SqlQuery<RawImage>(strCmd).ToList();
1347 if (rgImg ==
null || rgImg.Count == 0)
1366 List<RawImage> rgImg = entities.RawImages.AsNoTracking().Where(p => p.SourceID == nSrcId && p.TimeStamp == dt && p.Active ==
true).ToList();
1368 if (rgImg.Count == 0)
1389 public byte[]
GetRawImageData(RawImage img,
bool bLoadDataCriteria,
bool bLoadDebugData, out
byte[] rgDataCriteria, out
int? nDataCriteriaFmtId, out
byte[] rgDebugData, out
int? nDebugDataFmtId)
1391 if (img.VirtualID == 0)
1393 rgDataCriteria = (bLoadDataCriteria) ?
getRawImage(img.DataCriteria, img.OriginalSourceID) : img.DataCriteria;
1394 nDataCriteriaFmtId = img.DataCriteriaFormatID;
1395 rgDebugData = (bLoadDebugData) ?
getRawImage(img.DebugData, img.OriginalSourceID) : img.DebugData;
1396 nDebugDataFmtId = img.DebugDataFormatID;
1397 return getRawImage(img.Data, img.OriginalSourceID);
1402 List<RawImage> rgImg = entities.RawImages.AsNoTracking().Where(p => p.ID == img.VirtualID).ToList();
1404 if (rgImg.Count == 0)
1406 rgDataCriteria =
null;
1407 nDataCriteriaFmtId =
null;
1409 nDebugDataFmtId =
null;
1413 rgDataCriteria = (bLoadDataCriteria) ?
getRawImage(rgImg[0].DataCriteria, img.OriginalSourceID,
null, entities) : rgImg[0].DataCriteria;
1414 nDataCriteriaFmtId = rgImg[0].DataCriteriaFormatID;
1415 rgDebugData = (bLoadDebugData) ?
getRawImage(rgImg[0].DebugData, img.OriginalSourceID,
null, entities) : rgImg[0].DebugData;
1416 nDebugDataFmtId = rgImg[0].DebugDataFormatID;
1418 return getRawImage(rgImg[0].Data, img.OriginalSourceID,
null, entities);
1433 if (img.VirtualID == 0)
1435 nDataCriteriaFmtId = img.DataCriteriaFormatID;
1436 return getRawImage(img.DataCriteria, img.OriginalSourceID);
1441 List<RawImage> rgImg = entities.RawImages.AsNoTracking().Where(p => p.ID == img.VirtualID).ToList();
1443 if (rgImg.Count == 0)
1445 nDataCriteriaFmtId =
null;
1449 nDataCriteriaFmtId = rgImg[0].DataCriteriaFormatID;
1450 return getRawImage(rgImg[0].DataCriteria, img.OriginalSourceID,
null, entities);
1465 if (img.VirtualID == 0)
1467 nDebugDataFormatId = img.DebugDataFormatID;
1468 return getRawImage(img.DebugData, img.OriginalSourceID);
1473 List<RawImage> rgImg = entities.RawImages.AsNoTracking().Where(p => p.ID == img.VirtualID).ToList();
1475 if (rgImg.Count == 0)
1477 nDebugDataFormatId =
null;
1481 nDebugDataFormatId = rgImg[0].DebugDataFormatID;
1482 return getRawImage(rgImg[0].DebugData, img.OriginalSourceID,
null, entities);
1508 byte[] rgData =
null;
1512 var data = entities.RawImages.AsNoTracking().Where(p => p.ID == nImgID).Select(p =>
new { p.DebugData, p.VirtualID }).FirstOrDefault();
1513 if (data.DebugData ==
null)
1515 nImgID = data.VirtualID.GetValueOrDefault(0);
1519 rgData = entities.RawImages.AsNoTracking().Where(p => p.ID == nImgID).Select(p => p.DebugData).FirstOrDefault();
1525 rgData = data.DebugData;
1554 byte[] rgData =
null;
1558 var data = entities.RawImages.AsNoTracking().Where(p => p.ID == nImgID).Select(p =>
new { p.DataCriteria, p.VirtualID }).FirstOrDefault();
1559 if (data.DataCriteria ==
null)
1561 nImgID = data.VirtualID.GetValueOrDefault(0);
1565 rgData = entities.RawImages.AsNoTracking().Where(p => p.ID == nImgID).Select(p => p.DataCriteria).FirstOrDefault();
1571 rgData = data.DataCriteria;
1590 if (rgData ==
null || rgData.Length < 5)
1594 if (strFile ==
null)
1598 throw new Exception(
"You must open the database on a datasource.");
1601 if (nSecondarySrcId ==
null)
1607 if (bTestConnection)
1610 int nIdx = strFile1.IndexOf(strDbPath);
1612 strFile1 = strFile1.Substring(strDbPath.Length);
1615 return getRemoteData(strFile1, entities);
1625 if (!File.Exists(strPath + strFile))
1627 lock (m_objRawImgSync)
1629 int nSecondarySrcId1 = nSecondarySrcId.Value;
1631 if (m_rgSecondarySourcePath.ContainsKey(nSecondarySrcId1))
1648 return getRemoteData(strPath + strFile, entities);
1650 return File.ReadAllBytes(strPath + strFile);
1652 catch (Exception excpt)
1663 if (
string.IsNullOrEmpty(ci.
Password))
1669 private byte[] getRemoteData(
string strInfo, DNNEntities entities =
null)
1671 if (entities ==
null)
1672 entities = m_entities;
1674 string strCmd =
"EXEC [dbo].[GetRawData] @strInfo = N'" + strInfo +
"'";
1675 DbRawSqlQuery<byte[]> qry = entities.Database.SqlQuery<
byte[]>(strCmd);
1677 lock (m_objRemoteSync)
1679 return qry.Single();
1693 if (rgData.Length < 5)
1696 if (rgData[0] !=
'F' ||
1703 return Encoding.ASCII.GetString(rgData, 5, rgData.Length - 5);
1715 List<RawImage> rg = m_entities.RawImages.Where(p => p.ID == nID).ToList();
1720 if (rg[0].VirtualID == 0)
1723 rg[0].SourceID = nNewSrcID;
1726 m_entities.SaveChanges();
1741 List<RawImage> rg = m_entities.RawImages.Where(p => p.ID == nID).ToList();
1746 rg[0].ActiveLabel = nLabel;
1747 rg[0].Active = bActivate;
1750 m_entities.SaveChanges();
1762 string strCmd =
"UPDATE [dbo].[RawImages] SET [ActiveLabel] = " + nLabel.ToString() +
",[Active] = 1";
1763 strCmd +=
" WHERE ([ID] = " + nID.ToString() +
")";
1765 m_entities.Database.ExecuteSqlCommand(strCmd);
1776 string strCmd =
"UPDATE [dbo].[RawImages] SET [ActiveLabel] = " + nLabel.ToString() +
",[Active] = 1";
1777 strCmd +=
" WHERE ([SourceID] = " + nSrcId.ToString() +
") AND ([Idx] = " + nIdx.ToString() +
")";
1779 m_entities.Database.ExecuteSqlCommand(strCmd);
1790 string strCmd =
"UPDATE [dbo].[RawImages] SET [ActiveLabel] = " + nLabel.ToString() +
",[Active] = 1";
1791 strCmd +=
" WHERE ([SourceID] = " + nSrcId.ToString() +
")";
1793 if (nOriginalLabel.HasValue)
1794 strCmd +=
" AND ([OriginalLabel] = " + nOriginalLabel.Value.ToString() +
")";
1796 m_entities.Database.ExecuteSqlCommand(strCmd);
1805 string strCmd =
"UPDATE [dbo].[RawImages] SET [ActiveLabel] = [OriginalLabel], [Active] = 1";
1806 strCmd +=
" WHERE ([SourceID] = " + nSrcId.ToString() +
")";
1807 m_entities.Database.ExecuteSqlCommand(strCmd);
1816 public void DisableLabel(
int nSrcId,
int nLabel,
bool bOriginalLabel =
false)
1818 string strCmd =
"UPDATE [dbo].[RawImages] SET [Active] = 0";
1819 strCmd +=
" WHERE ([SourceID] = " + nSrcId.ToString() +
")";
1822 strCmd +=
" AND ([OriginalLabel] = " + nLabel.ToString() +
")";
1824 strCmd +=
" AND ([ActiveLabel] = " + nLabel.ToString() +
")";
1826 m_entities.Database.ExecuteSqlCommand(strCmd);
1835 string strCmd =
"UPDATE [dbo].[RawImages] SET [Active] = 0";
1836 strCmd +=
" WHERE ([SourceID] = " + nSrcId.ToString() +
")";
1837 m_entities.Database.ExecuteSqlCommand(strCmd);
1849 string strCmd =
"SELECT COUNT([ID]) FROM[DNN].[dbo].[RawImages] WHERE(SourceID = " + nSrcId.ToString() +
") AND (Width != " + nWidth.ToString() +
" OR Height != " + nHeight.ToString() +
")";
1850 DbRawSqlQuery<int> qry = m_entities.Database.SqlQuery<
int>(strCmd);
1851 List<int> rgVal = qry.ToList();
1852 int nCount = rgVal[0];
1854 strCmd =
"UPDATE [dbo].[RawImages] SET [Active] = 0 WHERE(SourceID = " + nSrcId.ToString() +
") AND (Width != " + nWidth.ToString() +
" OR Height != " + nHeight.ToString() +
")";
1855 m_entities.Database.ExecuteSqlCommand(strCmd);
1868 string strCmd =
"UPDATE [dbo].[RawImages] SET [Active] = " + ((bActive) ?
"1" :
"0");
1869 strCmd +=
" WHERE ([SourceID] = " + nSrcId.ToString() +
") AND ([Idx] = " + nIdx.ToString() +
")";
1871 m_entities.Database.ExecuteSqlCommand(strCmd);
1882 string strSql =
"UPDATE [dbo].[RawImages] SET [ActiveLabel] = " + nLabel.ToString() +
",[Active] = 1 WHERE (ID = " + nID.ToString() +
")";
1884 if (m_entities !=
null)
1886 m_entities.Database.ExecuteSqlCommand(strSql);
1892 entities.Database.ExecuteSqlCommand(strSql);
1904 List<RawImage> rg = m_entities.RawImages.Where(p => p.ID == nID).ToList();
1909 rg[0].Description = strDescription;
1910 m_entities.SaveChanges();
1925 List<RawImage> rg = entities.RawImages.Where(p => p.ID == nID).ToList();
1930 List<RawImageParameter> rgP = entities.RawImageParameters.Where(p => p.RawImageID == nID && p.Name == strParamName).ToList();
1935 if (rgP[0].TextValue ==
null || rgP[0].TextValue.Length == 0)
1938 if (rg[0].Description == rgP[0].TextValue)
1941 rg[0].Description = rgP[0].TextValue;
1942 entities.SaveChanges();
1959 public List<int>
QueryAllRawImageIDs(
int nSrcId = 0,
int nMax =
int.MaxValue,
int nLabel = -1,
int nBoost = -1,
bool bBoostIsExact =
false,
bool bAnnotatedOnly =
false,
bool bActiveOnly =
true)
1966 string strTop = (nMax ==
int.MaxValue) ?
"" :
"TOP " + nMax.ToString();
1967 string strCmd =
"SELECT " + strTop +
" ID FROM RawImages WHERE (SourceID = " + nSrcId.ToString() +
")";
1970 strCmd +=
" AND (ActiveLabel = " + nLabel.ToString() +
")";
1974 string strCompare = (bBoostIsExact) ?
"=" :
">=";
1975 strCmd +=
" AND (ActiveBoost " + strCompare +
" " + nBoost.ToString() +
")";
1979 strCmd +=
" AND (DataCriteriaFormatID = " + ((int)
SimpleDatum.
DATA_FORMAT.ANNOTATION_DATA).ToString() +
")";
1982 strCmd +=
" AND (Active = 1)";
1984 return entities.Database.SqlQuery<
int>(strCmd).ToList();
1998 public RawImage
CreateRawImage(
int nIdx,
SimpleDatum d,
int nBackgroundWritingThreadCount,
string strDescription =
null,
int? nOriginalSourceID =
null,
bool bActive =
true)
2000 if (
string.IsNullOrEmpty(strDescription))
2003 DateTime dtMin =
new DateTime(1980, 1, 1);
2004 RawImage img =
new RawImage();
2005 bool bEncoded =
false;
2008 img.Width = d.
Width;
2009 img.SourceID =
m_src.ID;
2012 img.OriginalBoost = (
short)d.
Boost;
2013 img.ActiveBoost = (short)d.
Boost;
2015 img.ActiveLabel = d.
Label;
2016 img.OriginalLabel = d.
Label;
2017 img.SourceID =
m_src.ID;
2018 img.Active = bActive;
2020 img.Description = strDescription;
2022 if (nOriginalSourceID.HasValue)
2023 img.OriginalSourceID = nOriginalSourceID.Value;
2025 string strGuid = Guid.NewGuid().ToString();
2036 img.Encoded = bEncoded;
2064 if (m_fileWriter ==
null)
2067 return m_fileWriter.WaitUntilCompletion(nWait);
2082 protected byte[]
setImageByteData(
byte[] rgImg,
string strType =
null,
string strGuid =
null,
int nBackgroundWritingThreadCount = 0)
2090 if (strGuid ==
null)
2091 strGuid = Guid.NewGuid().ToString();
2096 string strTypeExt = (strType ==
null) ?
"" :
"." + strType;
2097 string strFile = strGuid + strTypeExt +
".bin";
2099 if (nBackgroundWritingThreadCount > 0)
2101 if (m_fileWriter ==
null)
2102 m_fileWriter =
new FileWriter(nBackgroundWritingThreadCount);
2110 string strTag =
"FILE:" + strFile;
2111 return Encoding.ASCII.GetBytes(strTag);
2114 private void fileWriterThread()
2133 List<RawImage> rgImg = entities.RawImages.Where(p => p.SourceID ==
m_src.ID && p.Idx >= nIdx && p.Active ==
true).OrderBy(p => p.Idx).Take(nCount).ToList();
2139 List<int?> rgId =
new List<int?>();
2140 Dictionary<int, string> rgNames =
new Dictionary<int, string>();
2142 for (
int i=0; i<rgImg.Count; i++)
2144 if (evtCancel !=
null && evtCancel.WaitOne(0))
2147 strName = Guid.NewGuid().ToString();
2148 rgNames.Add(rgImg[i].ID, strName);
2150 rgId.Add(rgImg[i].ID);
2151 rgData = rgImg[i].Data;
2155 if (strPath ==
null)
2157 strImgPath = strName +
".bin";
2159 strTag =
"FILE:" + strImgPath;
2160 rgImg[i].Data = Encoding.ASCII.GetBytes(strTag);
2164 rgData = rgImg[i].DebugData;
2168 if (strPath ==
null)
2170 strImgPath = strName +
".dbg.bin";
2172 strTag =
"FILE:" + strImgPath;
2173 rgImg[i].DebugData = Encoding.ASCII.GetBytes(strTag);
2177 rgData = rgImg[i].DataCriteria;
2181 if (strPath ==
null)
2183 strImgPath = strName +
".criteria.bin";
2185 strTag =
"FILE:" + strImgPath;
2186 rgImg[i].DataCriteria = Encoding.ASCII.GetBytes(strTag);
2191 entities.SaveChanges();
2193 List<RawImageParameter> rgParam = entities.RawImageParameters.Where(p => rgId.Contains(p.RawImageID)).ToList();
2194 for (
int i = 0; i < rgParam.Count; i++)
2196 rgData = rgParam[i].Value;
2200 if (strPath ==
null)
2202 int nRawImgId = rgParam[i].RawImageID.GetValueOrDefault(0);
2203 string strName1 = rgNames[nRawImgId];
2204 strImgPath = strName1 +
".param_" + rgParam[i].Name +
".bin";
2206 strTag =
"FILE:" + strImgPath;
2207 rgParam[i].Value = Encoding.ASCII.GetBytes(strTag);
2212 entities.SaveChanges();
2233 List<RawImage> rgImg = entities.RawImages.Where(p => p.SourceID ==
m_src.ID && p.Idx >= nIdx && p.Active ==
true).OrderBy(p => p.Idx).Take(nCount).ToList();
2234 List<string> rgstrFiles =
new List<string>();
2237 List<int?> rgId =
new List<int?>();
2239 for (
int i = 0; i < rgImg.Count; i++)
2241 if (evtCancel !=
null && evtCancel.WaitOne(0))
2244 rgData = rgImg[i].Data;
2248 if (strPath !=
null)
2255 rgData = rgImg[i].DebugData;
2259 if (strPath !=
null)
2266 rgData = rgImg[i].DataCriteria;
2270 if (strPath !=
null)
2278 entities.SaveChanges();
2280 List<RawImageParameter> rgParam = entities.RawImageParameters.Where(p => rgId.Contains(p.RawImageID)).ToList();
2281 for (
int i = 0; i < rgParam.Count; i++)
2283 rgData = rgParam[i].Value;
2287 if (strPath !=
null)
2295 entities.SaveChanges();
2297 foreach (
string strFile
in rgstrFiles)
2299 File.Delete(strFile);
2331 List<RawImage> rgImg = entities.RawImages.Where(p => p.ID == nImageID).ToList();
2332 if (rgImg.Count > 0)
2335 int nVirtId = rgImg[0].VirtualID.GetValueOrDefault(0);
2339 List<RawImage> rgImg2 = entities.RawImages.Where(p => p.ID == nVirtId).ToList();
2340 if (rgImg2.Count > 0)
2345 rgImg[0].OriginalSourceID = nSecondarySrcId;
2346 entities.SaveChanges();
2350 else if (rgImg[0].Data !=
null)
2355 rgImg[0].OriginalSourceID = nSecondarySrcId;
2356 entities.SaveChanges();
2372 entities.Configuration.AutoDetectChangesEnabled =
false;
2373 entities.Configuration.ValidateOnSaveEnabled =
false;
2377 IQueryable<RawImageParameter> iquery = entities.RawImageParameters.Where(p => p.SourceID == param.
SourceID && p.RawImageID == param.
ImageID && p.Name == param.
Name);
2379 int nCount = iquery.Count();
2382 RawImageParameter rip =
new RawImageParameter();
2383 rip.RawImageID = param.
ImageID;
2384 rip.Name = param.
Name;
2386 rip.TextValue = param.
Value;
2388 rip.Value = param.
Data;
2389 entities.RawImageParameters.Add(rip);
2395 List<RawImageParameter> rg = iquery.ToList();
2396 rg[0].TextValue = param.
Value;
2398 rg[0].Value = param.
Data;
2403 entities.SaveChanges();
2417 entities.Configuration.AutoDetectChangesEnabled =
false;
2418 entities.Configuration.ValidateOnSaveEnabled =
false;
2420 foreach (RawImage img
in rgImg)
2423 entities.RawImages.Add(img);
2427 entities.SaveChanges();
2429 if (rgrgParam !=
null && rgrgParam.Count == rgImg.Count)
2431 for (
int i = 0; i < rgImg.Count; i++)
2433 for (
int j = 0; j < rgrgParam[i].Count; j++)
2436 string strName = p.
Name;
2437 string strVal = p.
Value;
2439 byte[] rgData = p.
Data;
2445 if (imgParam !=
null)
2447 strVal = imgParam.TextValue;
2448 rgData = imgParam.Value;
2452 if (!String.IsNullOrEmpty(strVal) || dfVal.HasValue || rgData !=
null)
2457 entities.SaveChanges();
2472 m_entities.RawImages.Add(img);
2473 m_entities.SaveChanges();
2477 string str = ((
Datum)d).Tag as string;
2478 string strName = ((
Datum)d).TagName;
2480 if (str !=
null && str.Length > 0 && strName !=
null && strName.Length > 0)
2498 List<RawImage> rgItems = entities.RawImages.AsNoTracking().Where(p => p.ID == nID).ToList();
2500 if (rgItems.Count == 0)
2519 return entities.RawImages.AsNoTracking().Where(p => p.SourceID == nSrcId).Count();
2532 string strCmd =
"DELETE FROM RawImages WHERE (SourceID = " + nSrcId.ToString() +
")";
2536 entities.Database.ExecuteSqlCommand(strCmd);
2539 if (strImgPath !=
null)
2540 deleteImages(strImgPath);
2544 private bool deleteImages(
string strPath)
2546 if (!Directory.Exists(strPath))
2549 string[] rgstrFiles = Directory.GetFiles(strPath);
2550 foreach (
string strFile
in rgstrFiles)
2552 File.Delete(strFile);
2555 Directory.Delete(strPath);
2569 string strCmd =
"DELETE FROM RawImageResults WHERE (SourceID = " + nSrcId.ToString() +
")";
2573 entities.Database.ExecuteSqlCommand(strCmd);
2590 List<RawImageMean> rgImg = entities.RawImageMeans.AsNoTracking().Where(p => p.SourceID == nSrcId).ToList();
2592 if (rgImg.Count == 0)
2620 IQueryable<RawImageMean> iQuery = entities.RawImageMeans.Where(p => p.SourceID == nSrcId);
2623 List<RawImageMean> rgMean = iQuery.ToList();
2624 RawImageMean im =
null;
2626 if (rgMean.Count == 0)
2627 im =
new RawImageMean();
2631 if (bUpdate || rgMean.Count == 0)
2633 bool bEncoded =
false;
2636 im.Width = sd.
Width;
2637 im.SourceID = nSrcId;
2642 if (rgMean.Count == 0)
2643 entities.RawImageMeans.Add(im);
2645 if (rgMean.Count == 0 || bUpdate)
2646 entities.SaveChanges();
2670 List<RawImageMean> rgDst = entities.RawImageMeans.Where(p => p.SourceID == nSrcIdDst).ToList();
2673 if (rgDst.Count == 0)
2675 dst =
new RawImageMean();
2676 dst.SourceID = nSrcIdDst;
2683 dst.Encoded = src.Encoded;
2684 dst.Channels = src.Channels;
2685 dst.Height = src.Height;
2686 dst.Width = src.Width;
2687 dst.Data = src.Data;
2689 if (rgDst.Count == 0)
2690 entities.RawImageMeans.Add(dst);
2692 entities.SaveChanges();
2707 string strCmd =
"DELETE FROM RawImageMeans WHERE (SourceID = " + nSrcId.ToString() +
")";
2711 entities.Database.ExecuteSqlCommand(strCmd);
2715 private IQueryable<RawImage> getQuery(IQueryable<RawImage> iQuery,
string strFilterVal,
int? nBoostVal)
2717 if (!
string.IsNullOrEmpty(strFilterVal))
2718 iQuery = iQuery.Where(p => p.Description == strFilterVal);
2720 if (nBoostVal.HasValue)
2722 if (nBoostVal.Value < 0)
2724 int nVal = Math.Abs(nBoostVal.Value);
2725 iQuery = iQuery.Where(p => p.ActiveBoost == nVal);
2729 int nVal = nBoostVal.Value;
2730 iQuery = iQuery.Where(p => p.ActiveBoost >= nVal);
2735 iQuery = iQuery.Where(p => p.ActiveBoost > 0);
2748 public int GetBoostCount(
int nSrcId = 0,
string strFilterVal =
null,
int? nBoostVal =
null)
2755 IQueryable<RawImage> iQuery = entities.RawImages.AsNoTracking().Where(p => p.SourceID == nSrcId && p.Active ==
true);
2756 iQuery = getQuery(iQuery, strFilterVal, nBoostVal);
2757 return iQuery.Count();
2775 if (!
string.IsNullOrEmpty(strFilterVal) || nBoostVal.HasValue)
2777 string strCmd1 =
"UPDATE[dbo].[RawImages] SET[Active] = 0 WHERE SourceID = " + nSrcId.ToString();
2778 entities.Database.ExecuteSqlCommand(strCmd1);
2780 string strCmd2 =
"UPDATE[dbo].[RawImages] SET[Active] = 1 WHERE SourceID = " + nSrcId.ToString();
2782 if (strFilterVal !=
null)
2783 strCmd2 +=
" AND Description = '" + strFilterVal +
"'";
2785 if (nBoostVal.HasValue)
2787 int nVal = nBoostVal.Value;
2791 nVal = Math.Abs(nVal);
2792 strCmd2 +=
" AND ActiveBoost = " + nVal.ToString();
2796 strCmd2 +=
" AND ActiveBoost >= " + nVal.ToString();
2800 entities.Database.ExecuteSqlCommand(strCmd2);
2804 string strCmd2 =
"UPDATE[dbo].[RawImages] SET[Active] = 1 WHERE SourceID = " + nSrcId.ToString();
2805 entities.Database.ExecuteSqlCommand(strCmd2);
2808 return entities.RawImages.Where(p => p.Active ==
true).Count();
2827 IQueryable<RawImage> iQuery = entities.RawImages.AsNoTracking().Where(p => p.SourceID == nSrcId);
2829 if (bActive && bInactive)
2830 return iQuery.Count();
2833 iQuery = iQuery.Where(p => p.Active ==
true);
2835 iQuery = iQuery.Where(p => p.Active ==
false);
2837 return iQuery.Count();
2848 public void ResetAllBoosts(
int nSrcId = 0,
int nMinBoost = 0,
bool bExactVal =
false,
int nDesiredBoostVal = -1)
2855 string strCmd =
"UPDATE RawImages SET ActiveBoost = ";
2857 if (nDesiredBoostVal >= 0)
2858 strCmd += nDesiredBoostVal.ToString();
2860 strCmd +=
"OriginalBoost";
2862 strCmd +=
" WHERE(SourceID = " + nSrcId.ToString();
2867 strCmd +=
" AND ActiveBoost = " + nMinBoost.ToString();
2869 strCmd +=
" AND ActiveBoost >= " + nMinBoost.ToString();
2874 entities.Database.ExecuteSqlCommand(strCmd);
2887 string strCmd =
"UPDATE RawImages SET ActiveBoost = " + nBoost.ToString() +
" WHERE (ID = " + nImageID.ToString() +
")";
2888 entities.Database.ExecuteSqlCommand(strCmd);
2899 public void UpdateBoosts(
int nSrcId, DateTime dtStart, DateTime dtEnd,
int nBoost)
2903 string strCmd =
"UPDATE RawImages SET ActiveBoost = " + nBoost.ToString() +
" WHERE (SourceID = " + nSrcId.ToString() +
" AND TimeStamp >= '" + dtStart.ToString() +
"' AND TimeStamp <= '" + dtEnd.ToString() +
"')";
2904 entities.Database.ExecuteSqlCommand(strCmd);
2917 if (nSrcId == 0 &&
m_src !=
null)
2925 log.
WriteLine(
"Resetting inactive indexes...");
2926 string strCmd =
"UPDATE [dbo].[RawImages] SET [Idx] = -1 WHERE SourceID = " + nSrcId.ToString() +
" AND Active = 0";
2927 entities.Database.ExecuteSqlCommand(strCmd);
2929 log.
WriteLine(
"Querying active images...");
2931 Stopwatch sw =
new Stopwatch();
2932 List<RawImage> rgImg = entities.RawImages.Where(p => p.SourceID == nSrcId && p.Active ==
true).OrderBy(p => p.TimeStamp).ThenBy(p => p.ID).ToList();
2937 for (
int i = 0; i < rgImg.Count; i++)
2939 rgImg[i].Idx = nIdx;
2943 entities.SaveChanges();
2945 if (sw.Elapsed.TotalMilliseconds > 1000)
2947 log.
Progress = ((double)i / (
double)rgImg.Count);
2956 entities.SaveChanges();
2972 List<RawImage> rgImg = entities.RawImages.Where(p => p.ID == nImageID).ToList();
2973 if (rgImg.Count > 0)
2975 if (rgImg[0].SourceID != nSrcID)
2977 if (rgImg[0].OriginalSourceID ==
null)
2978 rgImg[0].OriginalSourceID = rgImg[0].SourceID;
2980 rgImg[0].SourceID = nSrcID;
2982 entities.SaveChanges();
3002 List<RawImage> rgImg = entities.RawImages.Where(p => p.ID == nImageID).ToList();
3003 if (rgImg.Count == 0)
3006 if (rgImg[0].Active == bActivate)
3009 rgImg[0].Active = bActivate;
3012 entities.SaveChanges();
3026 if (rgSrcId.Length == 0)
3027 throw new Exception(
"You must specify at least one source iD.");
3031 string strActive = (bActive) ?
"1" :
"0";
3032 string strCmd =
"UPDATE RawImages SET [Active] = " + strActive +
" WHERE (";
3034 for (
int i=0; i<rgSrcId.Length; i++)
3036 strCmd +=
"SourceID = " + rgSrcId[i].ToString();
3038 if (i < rgSrcId.Length - 1)
3046 strCmd +=
" AND ([DataCriteriaFormatID] = 9)";
3047 strCmd +=
" AND (Convert(varbinary(8), [DataCriteria]) != 0x00000000)";
3050 entities.Database.ExecuteSqlCommand(strCmd);
3064 public void ActivateAllRawImages(
bool bActive,
bool bAnnotatedOnly,
int? nTgtLabel,
bool bTargetLabelExact,
int? nTgtBoost,
bool bTargetBoostExact, params
int[] rgSrcId)
3066 if (rgSrcId.Length == 0)
3067 throw new Exception(
"You must specify at least one source iD.");
3071 string strActive = (bActive) ?
"1" :
"0";
3072 string strCmd =
"UPDATE RawImages SET [Active] = " + strActive +
" WHERE (";
3074 for (
int i = 0; i < rgSrcId.Length; i++)
3076 strCmd +=
"SourceID = " + rgSrcId[i].ToString();
3078 if (i < rgSrcId.Length - 1)
3086 strCmd +=
" AND ([DataCriteriaFormatID] = 9)";
3087 strCmd +=
" AND (Convert(varbinary(8), [DataCriteria]) != 0x00000000)";
3090 if (nTgtLabel.HasValue)
3092 strCmd +=
" AND ([ActiveLabel] ";
3094 if (bTargetLabelExact)
3099 strCmd += nTgtLabel.Value.ToString() +
")";
3102 if (nTgtBoost.HasValue)
3104 strCmd +=
" AND ([ActiveBoost] ";
3106 if (bTargetBoostExact)
3111 strCmd += nTgtBoost.Value.ToString() +
")";
3114 entities.Database.ExecuteSqlCommand(strCmd);
3129 List<RawImage> rgImg = entities.RawImages.Where(p => p.ID == nImageId).ToList();
3130 if (rgImg.Count > 0)
3134 if (annotations.
Count > 0)
3135 rgImg[0].ActiveLabel = annotations[0].group_label;
3137 rgImg[0].ActiveLabel = 0;
3141 if (annotations.
Count > 0)
3148 rgImg[0].DataCriteria =
null;
3153 entities.SaveChanges();
3156 foreach (KeyValuePair<int, string> kv
in annotations.
Labels)
3158 List<Label> rgLabel = entities.Labels.Where(p => p.SourceID == nSrcId && p.Label1 == kv.Key).ToList();
3160 if (rgLabel.Count == 0)
3162 Label label =
new Label();
3163 label.Label1 = kv.Key;
3164 label.ActiveLabel = kv.Key;
3165 label.ImageCount = 0;
3166 label.SourceID = nSrcId;
3167 label.Name = kv.Value;
3168 entities.Labels.Add(label);
3172 rgLabel[0].Name = kv.Value;
3175 entities.SaveChanges();
3186 #region RawImage Results
3199 public int PutRawImageResults(
int nSrcId,
int nIdx,
int nLabel, DateTime dt, List<Result> rgResults,
bool bInvert, List<Tuple<DateTime, int>> rgExtra =
null)
3201 if (rgResults.Count == 0)
3202 throw new Exception(
"You must have at least one result!");
3206 List<RawImageResult> rg = entities.RawImageResults.Where(p => p.SourceID == nSrcId && p.Idx == nIdx).ToList();
3211 r =
new RawImageResult();
3213 r.SourceID = nSrcId;
3221 r.ResultCount = rgResults.Count;
3226 if (rgExtra !=
null && rgExtra.Count > 0)
3230 entities.RawImageResults.Add(r);
3232 entities.SaveChanges();
3248 public int PutRawImageResults(
int nSrcId,
int nIdx,
int nLabel, DateTime dt, List<Tuple<
SimpleDatum, List<Result>>> rgrgResults, List<Tuple<DateTime, int>> rgExtra =
null)
3250 if (rgrgResults.Count == 0 || rgrgResults[0].Item2.Count == 0)
3251 throw new Exception(
"You must have at least one result!");
3255 List<RawImageResult> rg = entities.RawImageResults.Where(p => p.SourceID == nSrcId && p.Idx == nIdx).ToList();
3260 r =
new RawImageResult();
3262 r.SourceID = nSrcId;
3270 r.ResultCount = rgrgResults[0].Item2.Count;
3273 r.BatchCount = rgrgResults.Count;
3275 if (rgExtra !=
null && rgExtra.Count > 0)
3279 entities.RawImageResults.Add(r);
3281 entities.SaveChanges();
3295 if (nBatchCount <= 0)
3296 throw new Exception(
"The batch count must be 1 or greater!");
3311 List<RawImageResult> rg = entities.RawImageResults.Where(p => p.ID == nRawImageResultID).ToList();
3315 rg[0].ExtraData = rgExtraData;
3316 entities.SaveChanges();
3329 public List<RawImageResult>
GetRawImageResults(
int nSrcId = 0,
bool bRequireExtraData =
false,
int nMax = -1)
3336 IQueryable<RawImageResult> iQry = entities.RawImageResults.AsNoTracking().Where(p => p.SourceID == nSrcId).OrderBy(p => p.TimeStamp);
3338 if (bRequireExtraData)
3339 iQry = iQry.Where(p => p.ExtraData !=
null);
3342 iQry = iQry.Take(nMax);
3344 return iQry.ToList();
3355 using (MemoryStream ms =
new MemoryStream())
3356 using (BinaryWriter bw =
new BinaryWriter(ms))
3360 for (
int i = 0; i < rg.Count; i++)
3362 bw.Write(rg[i].Item1.ToFileTimeUtc());
3363 bw.Write(rg[i].Item2);
3367 return ms.ToArray();
3378 List<Tuple<DateTime, int>> rgExtra =
new List<Tuple<DateTime, int>>();
3380 using (MemoryStream ms =
new MemoryStream(rg))
3381 using (BinaryReader br =
new BinaryReader(ms))
3383 int nCount = br.ReadInt32();
3385 for (
int i = 0; i < nCount; i++)
3387 long lTime = br.ReadInt64();
3388 int nLabel = br.ReadInt32();
3389 DateTime dt = DateTime.FromFileTimeUtc(lTime);
3391 rgExtra.Add(
new Tuple<DateTime, int>(dt, nLabel));
3404 #region RawImage Parameters
3417 List<RawImageParameter> rgP = entities.RawImageParameters.AsNoTracking().Where(p => p.RawImageID == nRawImageID && p.Name == strName).ToList();
3422 return rgP[0].TextValue;
3440 return int.Parse(str);
3474 return bool.Parse(str);
3487 List<RawImageParameter> rgP = entities.RawImageParameters.AsNoTracking().Where(p => p.RawImageID == nRawImageID && p.Name == strName).ToList();
3492 return getRawImage(rgP[0].Value,
null,
null, entities);
3506 List<RawImageParameter> rgP = entities.RawImageParameters.AsNoTracking().Where(p => p.RawImageID == nRawImageID && p.Name == strName).ToList();
3527 public int SetRawImageParameter(
int nRawImageID,
string strName,
string strValue,
double? dfVal =
null,
byte[] rgData =
null,
bool bSave =
true,
bool bOnlyAddNew =
false,
DNNEntities entities =
null)
3529 if (entities ==
null)
3530 entities = m_entities;
3532 List<RawImageParameter> rgP = entities.RawImageParameters.Where(p => p.RawImageID == nRawImageID && p.Name == strName).ToList();
3533 RawImageParameter riP =
null;
3537 riP =
new RawImageParameter();
3538 riP.RawImageID = nRawImageID;
3539 riP.SourceID =
m_src.ID;
3551 if (dfVal < -
float.MaxValue)
3552 fVal = -
float.MaxValue;
3553 else if (dfVal >
float.MaxValue)
3554 fVal =
float.MaxValue;
3556 fVal = (float)dfVal;
3558 riP.TextValue = strValue;
3559 riP.NumericValue2 = fVal;
3560 riP.NumericValue =
null;
3564 entities.RawImageParameters.Add(riP);
3567 entities.SaveChanges();
3582 public int SetRawImageParameter(
int nSrcId,
int nRawImageID,
string strName,
string strValue,
double? dfVal =
null,
byte[] rgData =
null)
3586 List<RawImageParameter> rgP = entities.RawImageParameters.Where(p => p.RawImageID == nRawImageID && p.Name == strName).ToList();
3587 RawImageParameter riP =
null;
3591 riP =
new RawImageParameter();
3592 riP.RawImageID = nRawImageID;
3593 riP.SourceID = nSrcId;
3601 riP.TextValue = strValue;
3602 riP.NumericValue2 = (float)dfVal;
3606 entities.RawImageParameters.Add(riP);
3608 entities.SaveChanges();
3625 List<RawImage> rg = m_entities.RawImages.Where(p => p.SourceID ==
m_src.ID && p.TimeStamp == dt).ToList();
3639 string strCmd =
"DELETE FROM RawImageParameters WHERE (SourceID = " + nSrcId.ToString() +
")";
3643 entities.Database.ExecuteSqlCommand(strCmd);
3661 if (strType.ToLower() ==
"text")
3662 return entities.RawImageParameters.AsNoTracking().Where(p => p.SourceID == nSrcId && p.Name == strName && p.TextValue !=
null).Count();
3664 if (strType.ToLower() ==
"numeric")
3665 return entities.RawImageParameters.AsNoTracking().Where(p => p.SourceID == nSrcId && p.Name == strName && p.NumericValue !=
null).Count();
3667 if (strType.ToLower() ==
"value")
3668 return entities.RawImageParameters.AsNoTracking().Where(p => p.SourceID == nSrcId && p.Name == strName && p.Value !=
null).Count();
3688 if (strType.ToLower() ==
"text")
3690 int nCount = entities.RawImageParameters.AsNoTracking().Where(p => p.SourceID == nSrcId && p.Name == strName && p.TextValue !=
null).Take(1).Count();
3691 return (nCount > 0) ? true :
false;
3694 if (strType.ToLower() ==
"numeric")
3696 int nCount = entities.RawImageParameters.AsNoTracking().Where(p => p.SourceID == nSrcId && p.Name == strName && p.NumericValue !=
null).Take(1).Count();
3697 return (nCount > 0) ? true :
false;
3700 if (strType.ToLower() ==
"value")
3702 int nCount = entities.RawImageParameters.AsNoTracking().Where(p => p.SourceID == nSrcId && p.Name == strName && p.Value !=
null).Take(1).Count();
3703 return (nCount > 0) ? true :
false;
3722 string strCmd =
"SELECT DISTINCT [TextValue] FROM RawImageParameters WHERE SourceID = " + nSrcId.ToString();
3723 DbRawSqlQuery<string> res = entities.Database.SqlQuery<
string>(strCmd);
3724 List<string> rgstr = res.ToList<
string>();
3726 List<string> rgstr1 =
new List<string>();
3728 foreach (
string str
in rgstr)
3730 if (str.Trim().Length > 0)
3744 #region RawImage Groups
3755 public int AddRawImageGroup(Image img,
int nIdx, DateTime dtStart, DateTime dtEnd, List<double> rgProperties)
3757 RawImageGroup g =
new RawImageGroup();
3761 g.StartDate = dtStart;
3764 if (rgProperties !=
null)
3766 if (rgProperties.Count > 0)
3767 g.Property1 = (decimal)rgProperties[0];
3769 if (rgProperties.Count > 1)
3770 g.Property2 = (decimal)rgProperties[1];
3772 if (rgProperties.Count > 2)
3773 g.Property3 = (decimal)rgProperties[2];
3775 if (rgProperties.Count > 3)
3776 g.Property4 = (decimal)rgProperties[3];
3778 if (rgProperties.Count > 4)
3779 g.Property5 = (decimal)rgProperties[4];
3794 List<RawImageGroup> rgG =
null;
3797 rgG = entities.RawImageGroups.Where(p => p.ID == g.ID).ToList();
3799 if (rgG !=
null && rgG.Count > 0)
3801 rgG[0].EndDate = g.EndDate;
3803 rgG[0].Property1 = g.Property1;
3804 rgG[0].Property2 = g.Property2;
3805 rgG[0].Property3 = g.Property3;
3806 rgG[0].Property4 = g.Property4;
3807 rgG[0].Property5 = g.Property5;
3808 rgG[0].Rating = g.Rating;
3809 rgG[0].RawData = g.RawData;
3810 rgG[0].StartDate = g.StartDate;
3814 entities.RawImageGroups.Add(g);
3817 entities.SaveChanges();
3834 List<RawImageGroup> rgG = entities.RawImageGroups.AsNoTracking().Where(p => p.Idx == nIdx && p.StartDate == dtStart && p.EndDate == dtEnd).ToList();
3865 string strCmd =
"DELETE FROM RawImageGroups";
3869 entities.Database.ExecuteSqlCommand(strCmd);
3881#pragma warning disable 1591
3883 public List<int> GetAllDataSourcesIDs()
3887 return entities.Sources.AsNoTracking().Select(p => p.ID).ToList();
3891#pragma warning restore 1591
3913 List<Source> rg = entities.Sources.Where(p => p.ID == nSrcId).ToList();
3917 rg[0].SaveImagesToFile = bSaveToFile;
3918 entities.SaveChanges();
3923 m_src.SaveImagesToFile = bSaveToFile;
3934 public void UpdateSource(
int nChannels,
int nWidth,
int nHeight,
bool bDataIsReal,
int nSrcId = 0)
3941 List<Source> rg = entities.Sources.Where(p => p.ID == nSrcId).ToList();
3945 rg[0].ImageChannels = nChannels;
3946 rg[0].ImageWidth = nWidth;
3947 rg[0].ImageHeight = nHeight;
3948 rg[0].ImageEncoded = bDataIsReal;
3949 entities.SaveChanges();
3955 m_src.ImageChannels = nChannels;
3956 m_src.ImageWidth = nWidth;
3957 m_src.ImageHeight = nHeight;
3958 m_src.ImageEncoded = bDataIsReal;
3971 int nSrcId =
m_src.ID;
3972 List<Source> rg = entities.Sources.Where(p => p.ID == nSrcId).ToList();
3976 rg[0].ImageCount = nImageCount;
3977 entities.SaveChanges();
3981 m_src.ImageCount = nImageCount;
3990 string strCmd =
"SELECT COUNT(ID) FROM RawImages WHERE (SourceID = " +
m_src.ID.ToString() +
" AND Active=1)";
3991 DbRawSqlQuery<int> result = m_entities.Database.SqlQuery<
int>(strCmd);
3992 List<int> rgResult = result.ToList();
3995 if (rgResult.Count > 0)
3996 nCount = rgResult[0];
4000 strCmd =
"SELECT COUNT(ID) FROM RawValues WHERE (SourceID = " +
m_src.ID.ToString() +
" AND Active=1)";
4001 result = m_entities.Database.SqlQuery<
int>(strCmd);
4002 rgResult = result.ToList();
4005 if (rgResult.Count > 0)
4006 nCount = rgResult[0];
4020 strName = convertWs(strName,
'_');
4053 strName = convertWs(strName,
'_');
4056 List<Source> rgSrc = entities.Sources.AsNoTracking().Where(p => p.Name == strName).ToList();
4058 if (rgSrc.Count == 0)
4075 List<Source> rgSrc = entities.Sources.AsNoTracking().Where(p => p.ID == nID).ToList();
4077 if (rgSrc.Count == 0)
4094 List<Source> rgSrc =
null;
4097 rgSrc = entities.Sources.Where(p => p.ID == src.ID).ToList();
4099 rgSrc = entities.Sources.Where(p => p.Name == src.Name).ToList();
4101 if (rgSrc !=
null && rgSrc.Count > 0)
4103 rgSrc[0].ImageChannels = src.ImageChannels;
4104 rgSrc[0].ImageCount = src.ImageCount;
4105 rgSrc[0].ImageEncoded = src.ImageEncoded;
4106 rgSrc[0].ImageHeight = src.ImageHeight;
4107 rgSrc[0].ImageWidth = src.ImageWidth;
4108 rgSrc[0].SaveImagesToFile = src.SaveImagesToFile;
4109 src.ID = rgSrc[0].ID;
4113 entities.Sources.Add(src);
4116 entities.SaveChanges();
4134 public int AddSource(
string strName,
int nChannels,
int nWidth,
int nHeight,
bool bDataIsReal,
int nCopyOfSourceID = 0,
bool bSaveImagesToFile =
true,
ConnectInfo ci =
null)
4136 Source src =
new Source();
4138 src.Name = convertWs(strName,
'_');
4139 src.ImageChannels = nChannels;
4140 src.ImageHeight = nHeight;
4141 src.ImageWidth = nWidth;
4142 src.ImageEncoded = bDataIsReal;
4144 src.SaveImagesToFile = bSaveImagesToFile;
4145 src.CopyOfSourceID = nCopyOfSourceID;
4169 strCmd =
"DELETE FROM Sources WHERE (ID = " + nSrcId.ToString() +
")";
4170 entities.Database.ExecuteSqlCommand(strCmd);
4172 strCmd =
"DELETE FROM SourceParameters WHERE (SourceID = " + nSrcId.ToString() +
")";
4173 entities.Database.ExecuteSqlCommand(strCmd);
4175 strCmd =
"DELETE FROM Labels WHERE (SourceID = " + nSrcId.ToString() +
")";
4176 entities.Database.ExecuteSqlCommand(strCmd);
4178 strCmd =
"IF OBJECT_ID (N'dbo.ValueItems', N'U') IS NOT NULL DELETE FROM ValueItems WHERE (SourceID = " + nSrcId.ToString() +
")";
4179 entities.Database.ExecuteSqlCommand(strCmd);
4181 strCmd =
"IF OBJECT_ID (N'dbo.ValueStreams', N'U') IS NOT NULL DELETE FROM ValueStreams WHERE (SourceID = " + nSrcId.ToString() +
")";
4182 entities.Database.ExecuteSqlCommand(strCmd);
4184 strCmd =
"IF OBJECT_ID (N'dbo.RawValues', N'U') IS NOT NULL DELETE FROM RawValues WHERE (SourceID = " + nSrcId.ToString() +
")";
4185 entities.Database.ExecuteSqlCommand(strCmd);
4199 List<string> rgstrSrc1 =
new List<string>();
4201 foreach (
string str
in rgstrSrc)
4203 rgstrSrc1.Add(convertWs(str,
'_'));
4208 foreach (
string str
in rgstrSrc1)
4210 List<Source> rgSrc = entities.Sources.Where(p => rgstrSrc.Contains(p.Name)).ToList();
4212 foreach (Source src
in rgSrc)
4265 List<SourceParameter> rgP = entities.SourceParameters.AsNoTracking().Where(p => p.SourceID == nSrcId).ToList();
4266 Dictionary<string, string> rgPval =
new Dictionary<string, string>();
4268 foreach (SourceParameter p
in rgP)
4270 rgPval.Add(p.Name, p.Value);
4285 strName = convertWs(strName,
'_');
4292 List<SourceParameter> rgP = entities.SourceParameters.AsNoTracking().Where(p => p.SourceID == nSrcId && p.Name == strName).ToList();
4297 return rgP[0].Value;
4310 strName = convertWs(strName,
'_');
4316 return int.Parse(strVal);
4328 strName = convertWs(strName,
'_');
4346 strName = convertWs(strName,
'_');
4352 return bool.Parse(strVal);
4363 strName = convertWs(strName,
'_');
4370 List<SourceParameter> rgP = entities.SourceParameters.Where(p => p.SourceID == nSrcId && p.Name == strName).ToList();
4371 SourceParameter sP =
null;
4375 sP =
new SourceParameter();
4377 sP.SourceID = nSrcId;
4384 sP.Value = strValue;
4387 entities.SourceParameters.Add(sP);
4389 entities.SaveChanges();
4406 IQueryable<RawImage> iquery = entities.RawImages.AsNoTracking().Where(p => p.SourceID == nSrcId).OrderBy(p => p.TimeStamp);
4407 if (strDesc !=
null)
4408 iquery = iquery.Where(p => p.Description == strDesc);
4410 List<RawImage> rgImages = iquery.Take(1).ToList();
4411 if (rgImages.Count == 0)
4412 return DateTime.MinValue;
4414 return rgImages[0].TimeStamp.GetValueOrDefault();
4431 IQueryable<RawImage> iquery = entities.RawImages.AsNoTracking().Where(p => p.SourceID == nSrcId).OrderByDescending(p => p.TimeStamp);
4432 if (strDesc !=
null)
4433 iquery = iquery.Where(p => p.Description == strDesc);
4435 List<RawImage> rgImages = iquery.Take(1).ToList();
4436 if (rgImages.Count == 0)
4437 return DateTime.MinValue;
4439 return rgImages[0].TimeStamp.GetValueOrDefault();
4452 public DateTime
GetLastTimeStamp(DateTime dtStart, DateTime dtEnd,
bool bEndInclusive,
int nSrcId = 0,
string strDesc =
null)
4459 IQueryable<RawImage> iquery;
4462 iquery = entities.RawImages.AsNoTracking().Where(p => p.SourceID == nSrcId && p.TimeStamp >= dtStart && p.TimeStamp <= dtEnd).OrderByDescending(p => p.TimeStamp);
4464 iquery = entities.RawImages.AsNoTracking().Where(p => p.SourceID == nSrcId && p.TimeStamp >= dtStart && p.TimeStamp < dtEnd).OrderByDescending(p => p.TimeStamp);
4466 if (strDesc !=
null)
4467 iquery = iquery.Where(p => p.Description == strDesc);
4469 List<RawImage> rgImages = iquery.Take(1).ToList();
4470 if (rgImages.Count == 0)
4471 return DateTime.MinValue;
4473 return rgImages[0].TimeStamp.GetValueOrDefault();
4493 IQueryable<RawImage> iquery = entities.RawImages.AsNoTracking().Where(p => p.SourceID == nSrcId).OrderByDescending(p => p.TimeStamp);
4494 if (strDesc !=
null)
4495 iquery = iquery.Where(p => p.Description == strDesc);
4497 List<RawImage> rgImages = iquery.Take(1).ToList();
4498 if (rgImages.Count == 0)
4499 return DateTime.MinValue;
4501 nIndex = rgImages[0].Idx.GetValueOrDefault(-1);
4503 return rgImages[0].TimeStamp.GetValueOrDefault();
4517 public DateTime
GetLastTimeStamp(DateTime dtStart, DateTime dtEnd,
bool bEndInclusive, out
int nIndex,
int nSrcId = 0,
string strDesc =
null)
4526 IQueryable<RawImage> iquery;
4529 iquery = entities.RawImages.AsNoTracking().Where(p => p.SourceID == nSrcId && p.TimeStamp >= dtStart && p.TimeStamp <= dtEnd).OrderByDescending(p => p.TimeStamp);
4531 iquery = entities.RawImages.AsNoTracking().Where(p => p.SourceID == nSrcId && p.TimeStamp >= dtStart && p.TimeStamp < dtEnd).OrderByDescending(p => p.TimeStamp);
4533 if (strDesc !=
null)
4534 iquery = iquery.Where(p => p.Description == strDesc);
4536 List<RawImage> rgImages = iquery.Take(1).ToList();
4537 if (rgImages.Count == 0)
4538 return DateTime.MinValue;
4540 nIndex = rgImages[0].Idx.GetValueOrDefault(-1);
4542 return rgImages[0].TimeStamp.GetValueOrDefault();
4562 int nTrainSrcID = 0;
4565 if (!String.IsNullOrEmpty(strTestSrc))
4568 if (!String.IsNullOrEmpty(strTrainSrc))
4573 List<Dataset> rgDs =
null;
4575 if (nTestSrcID != 0 && nTrainSrcID != 0)
4576 rgDs = entities.Datasets.AsNoTracking().Where(p => p.TrainingSourceID == nTrainSrcID && p.TestingSourceID == nTestSrcID).ToList();
4577 else if (nTestSrcID != 0)
4578 rgDs = entities.Datasets.AsNoTracking().Where(p => p.TestingSourceID == nTestSrcID).ToList();
4579 else if (nTrainSrcID != 0)
4580 rgDs = entities.Datasets.AsNoTracking().Where(p => p.TrainingSourceID == nTrainSrcID).ToList();
4582 if (rgDs !=
null && rgDs.Count > 0)
4583 return rgDs[0].Name;
4598 List<Dataset> rgDs = entities.Datasets.AsNoTracking().Where(p => p.TrainingSourceID == nSourceId || p.TestingSourceID == nSourceId).ToList();
4599 if (rgDs.Count == 0)
4614 strName = convertWs(strName,
'_');
4617 List<Dataset> rgDs = entities.Datasets.AsNoTracking().Where(p => p.Name == strName).ToList();
4619 if (rgDs.Count == 0)
4652 IQueryable<Dataset> iQuery = entities.Datasets.AsNoTracking().Where(p => p.ID == nID);
4654 if (iQuery.Count() == 0)
4657 List<Dataset> rgDs = iQuery.ToList();
4659 if (rgDs.Count == 0)
4673 strName = convertWs(strName,
'_');
4676 List<Dataset> rgDs = entities.Datasets.AsNoTracking().Where(p => p.Name == strName).ToList();
4678 if (rgDs.Count == 0)
4691 public Dataset
GetDataset(
string strTestingSrc,
string strTrainingSrc)
4698 List<Dataset> rgDs = entities.Datasets.AsNoTracking().Where(p => p.TestingSourceID == nTestingSrcId && p.TrainingSourceID == nTrainingSrcId).ToList();
4700 if (rgDs.Count == 0)
4719 public int AddDataset(
int nDsCreatorID,
string strName,
int nTestSrcId,
int nTrainSrcId,
int nDsGroupID = 0,
int nModelGroupID = 0,
ConnectInfo ci =
null,
bool bVerify =
true)
4721 strName = convertWs(strName,
'_');
4723 Source srcTest =
GetSource(nTestSrcId, ci);
4724 if (srcTest ==
null)
4725 throw new Exception(
"Could not find either the test source with ID = " + nTestSrcId.ToString() +
"!");
4727 Source srcTrain =
GetSource(nTrainSrcId, ci);
4728 if (srcTrain ==
null)
4729 throw new Exception(
"Could not find either the train source with ID = " + nTrainSrcId.ToString() +
"!");
4733 if (srcTest.ImageChannels.GetValueOrDefault() != srcTrain.ImageChannels.GetValueOrDefault())
4734 throw new Exception(
"The test and train sources have different image channels!");
4736 if (srcTest.ImageHeight.GetValueOrDefault() != srcTrain.ImageHeight.GetValueOrDefault())
4737 throw new Exception(
"The test and train sources have different image heights!");
4739 if (srcTest.ImageWidth.GetValueOrDefault() != srcTrain.ImageWidth.GetValueOrDefault())
4740 throw new Exception(
"The test and train sources have different image widths!");
4742 if (srcTest.ImageEncoded.GetValueOrDefault() != srcTrain.ImageEncoded.GetValueOrDefault())
4743 throw new Exception(
"The test and train sources have different image encodings!");
4750 List<Dataset> rgDs = entities.Datasets.Where(p => p.Name == strName && p.DatasetCreatorID == nDsCreatorID).ToList();
4760 ds.DatasetCreatorID = nDsCreatorID;
4764 double dfTotal = srcTest.ImageCount.GetValueOrDefault() + srcTrain.ImageCount.GetValueOrDefault();
4767 dfPct = srcTest.ImageCount.GetValueOrDefault() / dfTotal;
4769 ds.ImageChannels = srcTrain.ImageChannels;
4770 ds.ImageHeight = srcTrain.ImageHeight;
4771 ds.ImageWidth = srcTrain.ImageWidth;
4772 ds.ImageEncoded = srcTrain.ImageEncoded;
4773 ds.DatasetGroupID = nDsGroupID;
4774 ds.ModelGroupID = nModelGroupID;
4775 ds.TestingTotal = srcTest.ImageCount;
4776 ds.TrainingTotal = srcTrain.ImageCount;
4777 ds.TestingPercent = (decimal)dfPct;
4778 ds.Relabeled =
false;
4779 ds.TestingSourceID = srcTest.ID;
4780 ds.TrainingSourceID = srcTrain.ID;
4782 if (rgDs.Count == 0)
4783 entities.Datasets.Add(ds);
4785 entities.SaveChanges();
4806 List<Dataset> rgDs = entities.Datasets.Where(p => p.ID == nDsId).ToList();
4808 if (rgDs.Count == 0)
4811 rgDs[0].Description = strDesc;
4812 entities.SaveChanges();
4825 List<Dataset> rgDs = entities.Datasets.Where(p => p.ID == nDsId).ToList();
4827 if (rgDs.Count == 0)
4830 int nTestSrcId = rgDs[0].TestingSourceID.GetValueOrDefault();
4831 List<Source> rgSrcTest = entities.Sources.Where(p => p.ID == nTestSrcId).ToList();
4833 int nTrainSrcId = rgDs[0].TrainingSourceID.GetValueOrDefault();
4834 List<Source> rgSrcTrain = entities.Sources.Where(p => p.ID == nTrainSrcId).ToList();
4836 int nTestingTotal = rgSrcTest[0].ImageCount.GetValueOrDefault(0);
4837 int nTrainingTotal = rgSrcTrain[0].ImageCount.GetValueOrDefault(0);
4839 rgDs[0].TestingTotal = nTestingTotal;
4840 rgDs[0].TrainingTotal = nTrainingTotal;
4841 rgDs[0].TestingPercent = 0;
4843 if (nTrainingTotal + nTrainingTotal > 0)
4844 rgDs[0].TestingPercent = (decimal)nTestingTotal / (decimal)(nTestingTotal + nTrainingTotal);
4846 entities.SaveChanges();
4859 List<Dataset> rgDs =
null;
4862 rgDs = entities.Datasets.Where(p => p.ID == ds.ID).ToList();
4864 if (rgDs !=
null && rgDs.Count > 0)
4866 rgDs[0].DatasetGroupID = ds.DatasetGroupID;
4867 rgDs[0].Name = ds.Name;
4868 rgDs[0].TestingSourceID = ds.TestingSourceID;
4869 rgDs[0].TrainingSourceID = ds.TrainingSourceID;
4870 rgDs[0].DatasetCreatorID = ds.DatasetCreatorID;
4871 rgDs[0].ImageChannels = ds.ImageChannels;
4872 rgDs[0].ImageEncoded = ds.ImageEncoded;
4873 rgDs[0].ImageHeight = ds.ImageHeight;
4874 rgDs[0].ImageWidth = ds.ImageWidth;
4875 rgDs[0].ModelGroupID = ds.ModelGroupID;
4876 rgDs[0].TestingPercent = ds.TestingPercent;
4877 rgDs[0].TrainingTotal = ds.TrainingTotal;
4878 rgDs[0].TestingTotal = ds.TestingTotal;
4882 entities.Datasets.Add(ds);
4885 entities.SaveChanges();
4901 List<DatasetGroup> rgGroups = entities.DatasetGroups.AsNoTracking().Where(p => p.ID == nGroupID).ToList();
4903 if (rgGroups.Count == 0)
4919 List<DatasetGroup> rgGroups = entities.DatasetGroups.AsNoTracking().Where(p => p.ID == nGroupID).ToList();
4921 if (rgGroups.Count == 0)
4924 return rgGroups[0].Name;
4938 List<DatasetParameter> rgP = entities.DatasetParameters.AsNoTracking().Where(p => p.DatasetID == nDsId).ToList();
4939 Dictionary<string, string> rgDsP =
new Dictionary<string, string>();
4941 foreach (DatasetParameter p
in rgP)
4943 if (!rgDsP.ContainsKey(p.Name))
4944 rgDsP.Add(p.Name, p.Value);
4961 List<DatasetParameter> rgP = entities.DatasetParameters.AsNoTracking().Where(p => p.DatasetID == nDsId && p.Name == strName).ToList();
4966 return rgP[0].Value;
4984 return int.Parse(strVal);
5018 return bool.Parse(strVal);
5031 List<DatasetParameter> rgP = entities.DatasetParameters.Where(p => p.DatasetID == nDsId && p.Name == strName).ToList();
5032 DatasetParameter dsP =
null;
5036 dsP =
new DatasetParameter();
5038 dsP.DatasetID = nDsId;
5045 dsP.Value = strValue;
5048 entities.DatasetParameters.Add(dsP);
5050 entities.SaveChanges();
5065 entities.Configuration.AutoDetectChangesEnabled =
false;
5066 entities.Configuration.ValidateOnSaveEnabled =
false;
5068 foreach (KeyValuePair<string, string> kv
in rgP)
5070 DatasetParameter dsp =
new DatasetParameter();
5072 dsp.Value = kv.Value;
5073 dsp.DatasetID = nDsId;
5074 entities.DatasetParameters.Add(dsp);
5077 entities.SaveChanges();
5094 Source srcTraining =
GetSource(ds.TrainingSourceID.GetValueOrDefault());
5095 Source srcTesting =
GetSource(ds.TestingSourceID.GetValueOrDefault());
5100 entities.Database.CommandTimeout = 180;
5102 strCmd =
"DELETE RawImageParameters WHERE (SourceID = " + ds.TestingSourceID.GetValueOrDefault().ToString() +
") OR (SourceID = " + ds.TrainingSourceID.GetValueOrDefault().ToString() +
")";
5103 entities.Database.ExecuteSqlCommand(strCmd);
5105 strCmd =
"DELETE Labels WHERE (SourceID = " + ds.TestingSourceID.GetValueOrDefault().ToString() +
") OR (SourceID = " + ds.TrainingSourceID.GetValueOrDefault().ToString() +
")";
5106 entities.Database.ExecuteSqlCommand(strCmd);
5108 strCmd =
"DELETE RawImageMeans WHERE (SourceID = " + ds.TestingSourceID.GetValueOrDefault().ToString() +
") OR (SourceID = " + ds.TrainingSourceID.GetValueOrDefault().ToString() +
")";
5109 entities.Database.ExecuteSqlCommand(strCmd);
5111 strCmd =
"DELETE RawImageResults WHERE (SourceID = " + ds.TestingSourceID.GetValueOrDefault().ToString() +
") OR (SourceID = " + ds.TrainingSourceID.GetValueOrDefault().ToString() +
")";
5112 entities.Database.ExecuteSqlCommand(strCmd);
5114 strCmd =
"DELETE RawImages WHERE (SourceID = " + ds.TestingSourceID.GetValueOrDefault().ToString() +
") OR (SourceID = " + ds.TrainingSourceID.GetValueOrDefault().ToString() +
")";
5115 entities.Database.ExecuteSqlCommand(strCmd);
5117 strCmd =
"DELETE SourceParameters WHERE (SourceID = " + ds.TestingSourceID.GetValueOrDefault().ToString() +
") OR (SourceID = " + ds.TrainingSourceID.GetValueOrDefault().ToString() +
")";
5118 entities.Database.ExecuteSqlCommand(strCmd);
5120 strCmd =
"DELETE Sources WHERE (ID = " + ds.TestingSourceID.GetValueOrDefault().ToString() +
") OR (ID = " + ds.TrainingSourceID.GetValueOrDefault().ToString() +
")";
5121 entities.Database.ExecuteSqlCommand(strCmd);
5123 strCmd =
"DELETE DatasetParameters WHERE (DatasetID = " + ds.ID.ToString() +
")";
5124 entities.Database.ExecuteSqlCommand(strCmd);
5126 strCmd =
"DELETE Datasets WHERE (ID = " + ds.ID.ToString() +
")";
5127 entities.Database.ExecuteSqlCommand(strCmd);
5129 DeleteFiles del =
new DeleteFiles(log, evtCancel);
5131 if (srcTesting !=
null && !
string.IsNullOrEmpty(srcTesting.Name))
5132 del.DeleteDirectory(getImagePathBase(srcTesting.Name, entities));
5134 if (srcTraining !=
null && !
string.IsNullOrEmpty(srcTraining.Name))
5135 del.DeleteDirectory(getImagePathBase(srcTraining.Name, entities));
5148 if (nDatasetGroupID > 0)
5149 return entities.Datasets.AsNoTracking().Where(p => p.DatasetGroupID == nDatasetGroupID).ToList();
5151 return entities.Datasets.ToList();
5164 List<Dataset> rgDs =
new List<Dataset>();
5165 IQueryable<Dataset> iQuery = entities.Datasets.AsNoTracking().Where(p => p.DatasetCreatorID > 0);
5167 if (iQuery.Count() > 0)
5169 rgDs = iQuery.ToList();
5171 if (nDatasetGroupID > 0)
5172 return rgDs.Where(p => p.DatasetGroupID == nDatasetGroupID).ToList();
5189 if (bRelabeled.HasValue)
5191 bool bRelabeledValue = bRelabeled.Value;
5192 return entities.Datasets.AsNoTracking().Where(p => p.DatasetCreatorID == nDsCreatorID && p.Relabeled == bRelabeled).ToList();
5196 return entities.Datasets.Where(p => p.DatasetCreatorID == nDsCreatorID).ToList();
5210 List<DatasetGroup> rgGroups = entities.DatasetGroups.AsNoTracking().Where(p => p.Name == strName).ToList();
5212 if (rgGroups.Count == 0)
5215 return rgGroups[0].ID;
5230 if (ci !=
null && !
string.IsNullOrEmpty(ci.
Password))
5235 List<DatasetCreator> rgDsc = entities.DatasetCreators.AsNoTracking().Where(p => p.ID == nDatasetCreatorID).ToList();
5237 if (rgDsc.Count == 0)
5240 return rgDsc[0].Name;
5253 List<DatasetCreator> rgDsc = entities.DatasetCreators.AsNoTracking().Where(p => p.Name == strName).ToList();
5255 if (rgDsc.Count == 0)
5270 List<Dataset> rgDs = entities.Datasets.Where(p => p.DatasetCreatorID == nDsCreatorID && p.Relabeled ==
true).ToList();
5272 foreach (Dataset ds
in rgDs)
5274 ds.Relabeled =
false;
5277 entities.SaveChanges();
5290 List<Dataset> rgDs = entities.Datasets.Where(p => p.ID == nDsID).ToList();
5292 foreach (Dataset ds
in rgDs)
5294 ds.Relabeled = bRelabel;
5297 entities.SaveChanges();
5312 int nSrcTestId = ds.TestingSourceID.GetValueOrDefault();
5313 int nSrcTrainId = ds.TrainingSourceID.GetValueOrDefault();
5315 List<RawImage> rgImg = entities.RawImages.AsNoTracking().Where(p => p.SourceID == nSrcTestId || p.SourceID == nSrcTrainId).OrderBy(p => p.TimeStamp).Take(1).ToList();
5316 if (rgImg.Count == 0)
5317 return DateTime.MinValue;
5319 return rgImg[0].TimeStamp.GetValueOrDefault(DateTime.MinValue);
5334 int nSrcTestId = ds.TestingSourceID.GetValueOrDefault();
5335 int nSrcTrainId = ds.TrainingSourceID.GetValueOrDefault();
5337 List<RawImage> rgImg = entities.RawImages.AsNoTracking().Where(p => p.SourceID == nSrcTestId || p.SourceID == nSrcTrainId).OrderByDescending(p => p.TimeStamp).Take(1).ToList();
5338 if (rgImg.Count == 0)
5339 return DateTime.MinValue;
5341 return rgImg[0].TimeStamp.GetValueOrDefault(DateTime.MinValue);
5357 List<Dataset> rgDs = entities.Datasets.Where(p => p.DatasetCreatorID == nDatasetCreatorID).ToList();
5359 foreach (Dataset ds
in rgDs)
5361 bool bContainsDs =
false;
5363 Stopwatch sw =
new Stopwatch();
5367 log.
WriteLine(
"Aborting dataset count update.");
5371 if (rgstrDs !=
null)
5373 foreach (
string str
in rgstrDs)
5375 if (ds.Name.Contains(str))
5386 log.
WriteLine(
"Updating '" + ds.Name +
"'...");
5388 int nSrcIdTraining = ds.TrainingSourceID.GetValueOrDefault();
5389 if (nSrcIdTraining> 0)
5391 List<Source> rgSrc = entities.Sources.Where(p => p.ID == nSrcIdTraining).ToList();
5392 if (rgSrc.Count > 0)
5394 Source src = rgSrc[0];
5395 int nImageCount = entities.RawImages.Where(p => p.SourceID == nSrcIdTraining).Count();
5397 if (src.ImageCount != nImageCount)
5398 src.ImageCount = nImageCount;
5400 if (ds.TrainingTotal != nImageCount)
5401 ds.TrainingTotal = nImageCount;
5412 foreach (
int nID
in rgId)
5420 if (sw.Elapsed.TotalMilliseconds > 1000)
5422 log.
Progress = ((double)nIdx / (
double)rgId.Count);
5430 int nSrcIdTesting = ds.TestingSourceID.GetValueOrDefault();
5431 if (nSrcIdTesting > 0)
5433 List<Source> rgSrc = entities.Sources.Where(p => p.ID == nSrcIdTesting).ToList();
5434 if (rgSrc.Count > 0)
5436 Source src = rgSrc[0];
5437 int nImageCount = entities.RawImages.Where(p => p.SourceID == nSrcIdTesting).Count();
5439 if (src.ImageCount != nImageCount)
5440 src.ImageCount = nImageCount;
5442 if (ds.TestingTotal != nImageCount)
5443 ds.TestingTotal = nImageCount;
5454 foreach (
int nID
in rgId)
5462 if (sw.Elapsed.TotalMilliseconds > 1000)
5464 log.
Progress = ((double)nIdx / (
double)rgId.Count);
5472 double dfTestingPct = (double)ds.TestingTotal / (
double)(ds.TestingTotal + ds.TrainingTotal);
5473 if (ds.TestingPercent != (decimal)dfTestingPct)
5474 ds.TestingPercent = (decimal)dfTestingPct;
5476 entities.SaveChanges();
5491 List<ModelGroup> rgGroups = entities.ModelGroups.AsNoTracking().Where(p => p.ID == nGroupID).ToList();
5493 if (rgGroups.Count == 0)
5509 List<ModelGroup> rgGroups = entities.ModelGroups.AsNoTracking().Where(p => p.ID == nGroupID).ToList();
5511 if (rgGroups.Count == 0)
5514 return rgGroups[0].Name;
5527 List<ModelGroup> rgGroup = entities.ModelGroups.AsNoTracking().Where(p => p.Name == strGroup).ToList();
5528 if (rgGroup.Count == 0)
5531 return rgGroup[0].ID;
5544 return entities.Datasets.AsNoTracking().Where(p => p.ModelGroupID == nModelGroupId).ToList();
5559 foreach (Dataset ds
in rgDs)
5566 string strCmd =
"DELETE FROM ModelGroups WHERE ([Name] = '" + strGroup +
"')";
5567 entities.Database.ExecuteSqlCommand(strCmd);
5575#pragma warning disable 1591
5577 class FileDataCollection
5579 List<Tuple<string, byte[]>> m_rgData =
new List<Tuple<string, byte[]>>();
5580 object m_syncObj =
new object();
5582 public FileDataCollection()
5588 get {
return m_rgData.Count; }
5591 public void Add(
string strFile,
byte[] rgData)
5595 m_rgData.Add(
new Tuple<
string,
byte[]>(strFile, rgData));
5599 public Tuple<string, byte[]> Remove()
5603 if (m_rgData.Count == 0)
5606 Tuple<string, byte[]> item = m_rgData[0];
5607 m_rgData.RemoveAt(0);
5613 class FileWriter : IDisposable
5615 FileDataCollection m_rgData =
new FileDataCollection();
5616 Task[] m_rgFileWriterThreads =
null;
5617 ManualResetEvent m_evtCancelFileWriterThread =
new ManualResetEvent(
false);
5618 ManualResetEvent m_evtFileWriterDone =
new ManualResetEvent(
false);
5619 ManualResetEvent m_evtFileWriterEmpty =
new ManualResetEvent(
true);
5620 int m_nPeriod = 1000;
5621 int m_nThreads = 50;
5623 public FileWriter(
int nThreads = 50,
int nPeriod = 1000)
5625 m_nPeriod = nPeriod;
5626 m_nThreads = nThreads;
5629 public void Dispose()
5632 WaitUntilCompletion();
5634 if (m_rgFileWriterThreads !=
null)
5636 foreach (Task t
in m_rgFileWriterThreads)
5643 public void Cancel()
5645 m_evtCancelFileWriterThread.Set();
5648 public void Add(
string strPath,
byte[] rgData)
5650 m_evtFileWriterEmpty.Reset();
5651 m_rgData.Add(strPath, rgData);
5653 if (m_rgFileWriterThreads ==
null)
5655 m_evtCancelFileWriterThread.Reset();
5656 m_evtFileWriterDone.Reset();
5657 m_rgFileWriterThreads =
new Task[m_nThreads];
5659 for (
int i = 0; i < m_nThreads; i++)
5661 m_rgFileWriterThreads[i] = Task.Factory.StartNew(
new Action(fileWriterThread));
5666 public bool WaitUntilCompletion(
int nWait =
int.MaxValue)
5668 if (m_rgFileWriterThreads ==
null)
5671 if (m_evtFileWriterEmpty.WaitOne(nWait))
5677 private void fileWriterThread()
5681 int nWait = m_nPeriod;
5683 while (!m_evtCancelFileWriterThread.WaitOne(nWait))
5685 Tuple<string, byte[]> item = m_rgData.Remove();
5688 File.WriteAllBytes(item.Item1, item.Item2);
5694 m_evtFileWriterEmpty.Set();
5701 m_evtFileWriterDone.Set();
5706#pragma warning restore 1591
5714 string m_strValue =
null;
5715 double? m_dfValue =
null;
5716 byte[] m_rgValue =
null;
5718 bool m_bOnlyAddNew =
false;
5731 public ParameterData(
string strName,
string strValue,
double? dfVal =
null,
byte[] rgData =
null,
int nImageID = 0,
bool bOnlyAddNew =
false,
int nSrcId = 0)
5733 m_strName = strName;
5734 m_strValue = strValue;
5737 m_nImageID = nImageID;
5738 m_bOnlyAddNew = bOnlyAddNew;
5749 m_strName = strName;
5750 m_nImageID = nImageID;
5758 get {
return m_strName; }
5766 get {
return m_nSrcId; }
5767 set { m_nSrcId = value; }
5775 get {
return m_bOnlyAddNew; }
5783 get {
return m_strValue; }
5791 get {
return m_dfValue; }
5799 get {
return m_rgValue; }
5807 get {
return m_nImageID; }
5808 set { m_nImageID = value; }
5850 get {
return m_tag; }
5851 set { m_tag = value; }
5865 public int id {
get;
set; }
5872 get {
return virtualid.GetValueOrDefault(); }
5885 get {
return index.GetValueOrDefault(); }
5898 get {
return label.GetValueOrDefault(); }
5911 get {
return boost.GetValueOrDefault(); }
5924 get {
return time.GetValueOrDefault(); }
5930 public DateTime?
time {
get;
set; }
5937 get {
return desc; }
5963 get {
return active.GetValueOrDefault(
false); }
5977 return "Active=" +
Active.ToString() +
"; ID=" +
ID.ToString() +
"; Idx=" +
Index.ToString() +
"; Label=" +
Label.ToString() +
"; Time=" +
Time.ToString() +
"; Desc=" +
Desc +
"; Boost=" +
Boost.ToString();
Defines a collection of AnnotationGroups.
Dictionary< int, string > Labels
Get/set the label name mappings.
int Count
Specifies the number of items in the collection.
The BaseParameter class is the base class for all other parameter classes.
static double ParseDouble(string strVal)
Parse double values using the US culture if the decimal separator = '.', then using the native cultur...
The CancelEvent provides an extension to the manual cancel event that allows for overriding the manua...
bool WaitOne(int nMs=int.MaxValue)
Waits for the signal state to occur.
The ConnectInfo class specifies the server, database and username/password used to connect to a datab...
string Server
Get/set the server.
TYPE
Defines the generic connection location
override string ToString()
Returns a string representation of the connection.
string Password
Returns the password.
The Datum class is a simple wrapper to the SimpleDatum class to ensure compatibility with the origina...
The LabelMapping class represents a single label mapping.
int? ConditionBoostEquals
Get/set the boost condition to test which if met, the new label is set, otherwise it is not.
int NewLabel
Get/set the new label.
int? NewLabelConditionFalse
Get/set the label to use if the boost condition fails.
int OriginalLabel
Get/set the original label.
The Log class provides general output in text form.
void WriteLine(string str, bool bOverrideEnabled=false, bool bHeader=false, bool bError=false, bool bDisable=false)
Write a line of output.
double Progress
Get/set the progress associated with the Log.
The SimpleDatum class holds a data input within host memory.
static byte[] SaveAnnotationDataToDataCriteriaByteArray(ANNOTATION_TYPE type, AnnotationGroupCollection annotations)
Save the annotation data to a byte array.
ANNOTATION_TYPE
Specifies the annotation type when using annotations.
byte[] DebugData
Get/set debug data associated with the data.
int VirtualID
Returns the virtual ID of the SimpleDatum.
void SaveAnnotationDataToDataCriteria()
Save the annotation data and type to the data criteria.
DateTime TimeStamp
Get/set the Timestamp.
string Description
Get/set a description of the data.
static byte[] GetByteData(byte[] rgData, int nImagePadX, int nImagePadY, int nHeight, int nWidth, int nChannels)
Return the non-real data as a byte array after padding the data.
int Channels
Return the number of channels of the data.
bool IsRealData
Returns whether or not the data contains real numbers or byte data.
AnnotationGroupCollection annotation_group
When using annoations, each annotation group contains an annotation for a particular class used with ...
byte[] DataCriteria
Get/set data criteria associated with the data.
ANNOTATION_TYPE annotation_type
When using annotations, the annotation type specifies the type of annotation. Currently,...
DATA_FORMAT
Defines the data format of the DebugData and DataCriteria when specified.
int GroupID
Get/set the group ID of the SimpleDatum.
int Boost
Get/set the boost for this data.
int Width
Return the width of the data.
bool AutoLabeled
Get/set whether or not the label was auto generated.
DATA_FORMAT DebugDataFormat
Get/set the data format of the debug data.
int Height
Return the height of the data.
DATA_FORMAT DataCriteriaFormat
Get/set the data format of the data criteria.
int Label
Return the known label of the data.
The ResultDescriptor class describes the results of a run.
static byte[] CreateResults(List< Result > rgResults, bool bInvert)
The CreateResults function converts the list of (int nLabel, double dfResult) pairs into a array of b...
static List< Result > GetResults(byte[] rgData)
Extract the results from the binary data.
The DNNEntities class defines the entities used to connecto the database via Entity Frameworks.
The Database class manages the actual connection to the physical database using Entity Framworks from...
Dataset GetDataset(int nID, ConnectInfo ci=null)
Returns the Dataset entity for a dataset ID.
int GetLabelCount(int nLabel)
Returns the number of images under a given label.
void ActivateRawImageByIndex(int nSrcId, int nIdx, bool bActive)
Activate/deactivate a raw image based on its index.
bool ChangeRawImageSourceID(int nID, int nNewSrcID, bool bSave=true)
Change the data source ID on a raw image - currently only allowed on virtual raw images.
double GetDatasetParameter(int nDsId, string strName, double dfDefault)
Returns the value of a dataset parameter as a double.
void ActivateAllRawImages(bool bActive, bool bAnnotatedOnly, params int[] rgSrcId)
Activate all raw images associated with a set of source ID's.
int GetBoostCount(int nSrcId=0, string strFilterVal=null, int? nBoostVal=null)
Return the number of boosted images for a data source.
DateTime GetDatasetMaximumTimestamp(int nDsID)
Returns the maximum time-stamp for a dataset.
void SetSourceParameter(string strName, string strValue, int nSrcId=0)
Set the value of a data source parameter.
FORCE_LOAD
Defines the force load type.
string GetDatasetCreatorName(int nDatasetCreatorID, ConnectInfo ci=null)
Returns the name of a dataset creator given its ID.
List< RawImage > GetRawImagesAt(int nIdx, int nCount, int nSrcId=0, string strDescription=null)
Returns a list of RawImages from the database for a data source.
void UpdateSourceCounts(int nImageCount, ConnectInfo ci=null)
Updates the source counts for the open data source.
string GetDatabaseImagePath(string strName)
Query the physical database file path for Images.
Source m_src
Specifies the default data source.
List< Tuple< SimpleDatum, List< Result > > > GetRawImageResultBatch(int nBatchCount, byte[] rgResults)
Extracts the raw image result batch from the result binary data.
static byte[] PackExtraData(List< Tuple< DateTime, int > > rg)
Pack the extra data into a byte array.
void ResetLabelBoosts(int nProjectId)
Reset all label boosts to their orignal settings for a project.
byte[] GetRawImageDebugData(byte[] rgData, int? nOriginalSourceID=null)
Converts the raw image debug data which may be stored as a path to the underlying data file,...
byte[] GetRawImageDataCriteria(byte[] rgData, int? nOriginalSourceID=null)
Converts the raw image data criteria data which may be stored as a path to the underlying data file,...
void AddLabelToCache(int nLabel)
Adds a label to the label cache.
void UpdateActiveLabelByIndex(int nSrcId, int nIdx, int nLabel)
Update the label value of a label.
virtual void DeleteDataset(string strDsName, bool bDeleteRelatedProjects, Log log, CancelEvent evtCancel)
Delete a dataset.
void DisableLabel(int nSrcId, int nLabel, bool bOriginalLabel=false)
Disable a set of labels within the source specified by the ID.
virtual void Open(int nSrcId, FORCE_LOAD nForceLoad=FORCE_LOAD.NONE, ConnectInfo ci=null)
Opens a data source.
List< Dataset > GetAllDatasetsWithCreators(int nDatasetGroupID)
Returns a list of all datasets within a group with dataset creators.
List< RawImage > QueryRawImages(int nSrcId, bool? bActive=null, int nBoostVal=0, bool bExactBoostVal=false)
Returns the list of raw images that have a source ID from a selected list.
void SetLabelMapping(LabelMapping map, int nSrcId=0)
Saves a label mapping in the database for a data source.
bool ConvertRawImagesSaveToFile(int nIdx, int nCount, CancelEvent evtCancel=null)
The ConvertRawImagesSaveToFile method saves the image in the database to the file system and replaces...
void UpdateLabelCounts(Dictionary< int, int > rgCounts, int nSrcId=0)
Update the label counts for a given data source.
List< RawImageParameter > QueryRawImageParameters(int nImageID)
Query all image parameters for a given image.
void Open(string strSrc, bool bForceLoadImageFilePath=false)
Opens a data source.
void ActivateLabels(List< int > rgLabels, bool bActive, params int[] rgSrcId)
Activate (or deactivate) the labels specified for each of the source ID's specified.
bool UpdateRawImageDescriptionFromParameter(int nID, string strParamName)
Update the RawImage description from a RawImage parameter.
bool GetRawImageParameterExist(string strName, int nSrcId=0, string strType="TEXT")
Returns whether or not a given RawImage parameter exists.
RawImageGroup FindRawImageGroup(int nIdx, DateTime dtStart, DateTime dtEnd)
Searches for a RawImageGroup by index, start time-stamp and end time-stamp.
bool UpdateActiveLabel(int nID, int nLabel, bool bActivate=true, bool bSaveChanges=true)
Update the label value of a label.
int SetRawImageParameter(int nRawImageID, string strName, string strValue, double? dfVal=null, byte[] rgData=null, bool bSave=true, bool bOnlyAddNew=false, DNNEntities entities=null)
Add a new RawImage parameter (or update an existing if found).
int GetDatasetCreatorID(string strName)
Returns the ID of a dataset creator given its name.
bool ConvertRawImagesSaveToDatabase(int nIdx, int nCount, CancelEvent evtCancel=null)
The ConvertRawImagesSaveToDatabase method saves the image in the file system to the database and dele...
List< Label > GetLabels(bool bSort=true, bool bWithImagesOnly=false, int nSrcId=0, ConnectInfo ci=null)
Returns a list of all labels used by a data source.
Dataset GetDataset(string strName)
Returns the Dataset entity for a dataset name.
virtual void Close()
Close the previously opened data source.
void UpdateLabelCounts(int nSrcId=0, int nProjectId=0, ConnectInfo ci=null)
Update the label counts for a given data source and project (optionally) by querying the database for...
int PutSource(Source src, ConnectInfo ci=null)
Adds or updates (if exists) a data source to the database.
Source CurrentSource
Returns the current entity framwork Source object set during the previous call to Open().
int AddSource(string strName, int nChannels, int nWidth, int nHeight, bool bDataIsReal, int nCopyOfSourceID=0, bool bSaveImagesToFile=true, ConnectInfo ci=null)
Adds a new data source to the database.
int PutDataset(Dataset ds)
Save the Dataset entity to the database.
bool GetSourceParameter(string strName, bool bDefault, int nSrcId=0)
Return the data source parameter as a bool.
void DeleteModelGroup(string strGroup, Log log, CancelEvent evtCancel)
Deletes a model group from the database.
int SetRawImageParameter(int nSrcId, int nRawImageID, string strName, string strValue, double? dfVal=null, byte[] rgData=null)
Add a new RawImage parameter (or update an existing if found).
byte[] getRawImage(byte[] rgData, int? nSecondarySrcId=null, ConnectInfo ci=null, DNNEntities entities=null, bool bTestConnection=false)
Converts a set of bytes from a file path-name by loading its bytes and returning them,...
DateTime GetLastTimeStamp(int nSrcId=0, string strDesc=null)
Returns the last time-stamp in the data source.
RawImageParameter GetRawImageParameterEx(int nRawImageID, string strName)
Returns the RawImageParameter entity given the image ID and parameter name..
int GetRawImageParameterCount(string strName, int nSrcId=0, string strType="TEXT")
Returns the RawImage parameter count for a data source.
int m_nLastIndex
Specifies the last index added to the data source.
string GetDatasetGroupName(int nGroupID)
Returns the name of a dataset group given its ID.
List< RawImageResult > GetRawImageResults(int nSrcId=0, bool bRequireExtraData=false, int nMax=-1)
Returns the RawImageResults for a data source.
void DeleteSourceData(string strSrc)
Delete the data source data (images, means, results and parameters) from the database.
bool VerifyDataConnection(string strSrc, ConnectInfo ci)
Verify the data connection information.
Label GetLabel(int nID)
Return the Label with the given ID.
void SetDatasetParameters(int nDsId, Dictionary< string, string > rgP)
Adds a batch of new parametes.
List< DbItem > GetAllRawImageIndexes(bool bBoostedOnly, bool bIncludeActive=true, bool bIncludeInactive=false)
Returns the list of the image indexes of all images.
void UpdateLabelName(int nLabel, string strName, int nSrcId=0)
Update the name of a label.
void SaveLabelCache()
Saves the label cache to the database.
byte[] GetRawImageParameterData(int nRawImageID, string strName)
Return the byte array data of a RawImage parameter.
bool m_bEnableFileBasedData
Specifies whether or not file based data is enabled.
bool UpdateRawImageSourceID(int nImageID, int nSrcID)
Updates a given image's source ID.
double GetRawImageParameter(int nRawImageID, string strName, double dfDefault)
Return the double value of a RawImage parameter.
string m_strSecondaryImgPath
Specifies the secondary base path to the file based data (used when copying a data source)
double GetSourceParameter(string strName, double dfDefault, int nSrcId=0)
Return the data source parameter as a double.
string GetDatasetName(int nID, ConnectInfo ci=null)
Returns the name of a dataset given its ID.
void Refresh()
Close and re Open with the current data source.
void UpdateSaveImagesToFile(bool bSaveToFile, int nSrcId=0)
Update the SaveImagesToFile flag in a given Data Source.
DateTime GetLastTimeStamp(DateTime dtStart, DateTime dtEnd, bool bEndInclusive, int nSrcId=0, string strDesc=null)
Returns the last time-stamp in the data source.
void DeleteRawImages(int nSrcId=0)
Delete all RawImages in a data source.
void ResetAllBoosts(int nSrcId=0, int nMinBoost=0, bool bExactVal=false, int nDesiredBoostVal=-1)
Reset all image boosts for a data set.
RawImage GetRawImage(int nID)
Returns the RawImage with a given ID.
List< string > GetRawImageDistinctParameterDescriptions(int nSrcId=0)
Returns a list of distinct RawImage parameter descriptions for a data source.
virtual bool DeleteSourceData(int nSrcId=0)
Delete the data source data (images, means, results and parameters) from the database.
virtual bool DeleteSource(int nSrcId=0)
Delete a data source from the database.
static List< Tuple< DateTime, int > > UnpackExtraData(byte[] rg)
Unpack the extra data from a byte array.
int GetRawImageParameter(int nRawImageID, string strName, int nDefault)
Return the int value of a RawImage parameter.
RawImageMean GetRawImageMean(int nSrcId=0, ConnectInfo ci=null)
Return the RawImageMean for the image mean from the open data source.
string GetSourceParameter(string strName, int nSrcId=0)
Return the data source parameter as a string.
void ResetLabels(int nProjectId=0, int nSrcId=0)
Resets all labels back to their original labels for a project.
void DeleteLabelBoosts(int nProjectId, int nSrcId=0)
Delete all label boosts for a project.
void ActivateAllRawImages(bool bActive, bool bAnnotatedOnly, int? nTgtLabel, bool bTargetLabelExact, int? nTgtBoost, bool bTargetBoostExact, params int[] rgSrcId)
Activate all raw images associated with a set of source ID's.
int AddRawImageGroup(Image img, int nIdx, DateTime dtStart, DateTime dtEnd, List< double > rgProperties)
Adds a new RawImage group to the database.
void ResetAllActiveLabels(int nSrcId)
Reset the all active labels to their original label within a source.
int GetSourceID(string strName, ConnectInfo ci=null)
Returns the ID of a data source given its name.
void UpdateLabelMapping(int nNewLabel, List< int > rgOriginalLabels, int nSrcId=0)
Update a label mapping in the database for a data source.
Dictionary< string, string > GetDatasetParameters(int nDsId, ConnectInfo ci=null)
Returns all dataset parameters for a given dataset.
void SetDatasetParameter(int nDsId, string strName, string strValue)
Adds a new parameter or Sets the value of an existing dataset parameter.
void FixupRawImageCopy(int nImageID, int nSecondarySrcId)
The FixupRawImageCopy method is used to fixup the OriginalSourceId by setting it to a secondary sourc...
int GetDatasetParameter(int nDsId, string strName, int nDefault)
Returns the value of a dataset parameter as an int.
int DisableAllNonMatchingImages(int nSrcId, int nWidth, int nHeight)
Disable all images that do not have a matching widxht size.
Dictionary< string, string > GetSourceParameters(int nSrcId=0, ConnectInfo ci=null)
Returns a dictionary of the data source parameters.
int FindDatasetFromSourceId(int nSourceId)
Searches for the dataset containing the sourceId.
List< int > QueryAllRawImageIDs(int nSrcId=0, int nMax=int.MaxValue, int nLabel=-1, int nBoost=-1, bool bBoostIsExact=false, bool bAnnotatedOnly=false, bool bActiveOnly=true)
Returns the ID's of all RawImages within a data source.
string GetModelGroupName(int nGroupID)
Returns the name of a model group given its ID.
void DeleteSourceData()
Deletes the data source data for the open data source.
int AddDataset(int nDsCreatorID, string strName, int nTestSrcId, int nTrainSrcId, int nDsGroupID=0, int nModelGroupID=0, ConnectInfo ci=null, bool bVerify=true)
Add a new (or update an existing if exists) dataset to the database.
int FindRawImageGroupID(int nIdx, DateTime dtStart, DateTime dtEnd)
Searches fro the RawImageGroup ID.
List< RawImageParameter > QueryRawImageParameters(int nSrcId, string strName)
Query a list of all raw image parameters of a give name stored with a given source ID.
int GetDatasetID(string strName, ConnectInfo ci=null)
Returns a datasets ID given its name.
void AddLabelBoost(int nProjectId, int nLabel, double dfBoost, int nSrcId=0)
Add a label boost to the database for a given project.
void DisableAllLabels(int nSrcId)
Disable all labels within the source specified by the ID.
int QueryRawImageCount(int nSrcId=0)
Returns the number of RawImages in a data source.
ModelGroup GetModelGroup(int nGroupID, ConnectInfo ci=null)
Returns the ModelGroup entity given the ID of a model group.
DateTime GetLastTimeStamp(DateTime dtStart, DateTime dtEnd, bool bEndInclusive, out int nIndex, int nSrcId=0, string strDesc=null)
Returns the last time-stamp and index in the data source falling within a time range.
void UpdateAllActiveLabels(int nSrcId, int nLabel, int? nOriginalLabel)
Update the all items to a label value for the given nSrcId.
void DeleteLabelBoosts(int nProjectId)
Delete all label boosts for a project.
byte[] GetRawImageDataCriteria(RawImage img, out int? nDataCriteriaFmtId)
Returns the raw data criteria data of the RawImage.
int GetDatasetGroupID(string strName)
Returns the ID of a dataset group given its name.
void UpdateDatasetImageAnnotations(int nSrcId, int nImageId, AnnotationGroupCollection annotations, bool bSetLabelOnly)
Update the annotations of a given raw image.
Source GetSource(string strName, ConnectInfo ci=null)
Returns the Source entity given a data source name.
List< RawImage > GetRawImagesAtID(List< int > rgImageID, int nSrcId=0, string strDescription=null)
Returns a list of RawImages from the database for a data source.
void UpdateActiveLabelDirect(int nID, int nLabel)
Directly update the active label and activate the image with the specified ID.
RawImage CreateRawImage(int nIdx, SimpleDatum d, int nBackgroundWritingThreadCount, string strDescription=null, int? nOriginalSourceID=null, bool bActive=true)
Create a new RawImage but do not add it to the database.
string m_strPrimaryImgPath
Specifies the base path to the file based data.
void UpdateDatasetDescription(int nDsId, string strDesc)
Update the description of a given dataset.
void PutRawImages(List< RawImage > rgImg, List< List< ParameterData > > rgrgParam=null, ConnectInfo ci=null)
Saves a List of RawImages to the database.
void UpdateSource(int nChannels, int nWidth, int nHeight, bool bDataIsReal, int nSrcId=0)
Updates a data source.
int GetLabelID(int nLabel)
Returns the label ID associated with a label value.
byte[] GetRawImageDebugData(int nImgID, int? nOriginalSourceID=null)
Queries the Debug Data for an image an Converts the raw image data criteria data which may be stored ...
int PutRawImageResults(int nSrcId, int nIdx, int nLabel, DateTime dt, List< Tuple< SimpleDatum, List< Result > > > rgrgResults, List< Tuple< DateTime, int > > rgExtra=null)
Save the results of a Run as a RawImageResult.
RawImage GetRawImageAt(int nIdx, int nSrcId=0)
Returns the RawImage at a given image index.
bool UpdateRawImageDescription(int nID, string strDescription)
Update the description of a RawImage.
void DeleteRawImageParameters(int nSrcId)
Delete all RawImage parameters within a data source.
bool GetRawImageParameter(int nRawImageID, string strName, bool bDefault)
Return the bool value of a RawImage parameter.
int PutRawImageResults(int nSrcId, int nIdx, int nLabel, DateTime dt, List< Result > rgResults, bool bInvert, List< Tuple< DateTime, int > > rgExtra=null)
Save the results of a Run as a RawImageResult.
List< RawImage > GetRawImagesAt(List< int > rgImageIdx, int nSrcId=0, string strDescription=null)
Returns a list of RawImages from the database for a data source.
string GetLabelName(int nLabel, int nSrcId=0)
Get the Label name of a label within a data source.
void UpdateDatasetCounts(int nDsId, ConnectInfo ci=null)
Update the dataset counts.
int GetRawImageID(DateTime dt, int nSrcId=0)
Returns the RawImage ID for the image with the given time-stamp.
void ResetAllDatasetRelabelWithCreator(int nDsCreatorID)
Reset all dataset relabel flags with a given creator.
int GetImageCount()
Returns the number of raw images in the database for the open data source.
string getImagePath(byte[] rgData)
Returns the file path contained within a byte array or null if no path is found.
void Dispose()
Release any resources used.
int AddLabel(int nLabel, string strName="", int nSrcId=0, ConnectInfo ci=null)
Add a label to the database for a data source.
int LastIndex
Returns the last image index added to the database.
void DeleteSources(params string[] rgstrSrc)
Delete the list of data sources, listed by name, from the database.
bool GetDatasetParameter(int nDsId, string strName, bool bDefault)
Returns the value of a dataset parameter as a bool.
int ActivateFiltered(int nSrcId=0, string strFilterVal=null, int? nBoostVal=null)
Activate the images that meet the filtering criteria in the Data Source. If no filtering criteria is ...
List< Dataset > GetAllDatasetsInModelGroup(int nModelGroupId)
Returns all Dataset entities within a given model group.
byte[] setImageByteData(byte[] rgImg, string strType=null, string strGuid=null, int nBackgroundWritingThreadCount=0)
When enabled, saves the bytes to file and returns the file name of the binary file saved as an array ...
bool ActivateRawImage(int nImageID, bool bActivate, bool bSave=true)
Activate/Deactivate a given image.
void UpdateDatasetCounts(CancelEvent evtCancel, Log log, int nDatasetCreatorID, List< string > rgstrDs, string strParamNameForDescription)
Updates the dataset counts for a set of datasets.
void LoadLabelCounts(Dictionary< int, int > rgCounts, int nSrcId=0)
Load the label counts from the database for a data source.
virtual void setImagePath(FORCE_LOAD nForceLoad)
Sets the image path member to the path used when saving binary data to the file system.
void UpdateSourceCounts(ConnectInfo ci=null)
Updates the source counts for the open data source by querying the database for the counts.
byte[] GetRawImageDebugData(RawImage img, out int? nDebugDataFormatId)
Returns the raw debug data data of the RawImage.
string GetLabelBoostsAsText(int nProjectId, int nSrcId=0, bool bSort=true)
Returns the Label boosts as a string.
int SetRawImageParameterAt(DateTime dt, string strName, string strValue, double? dfVal, byte[] rgData)
Set the RawImage parameter for all RawImages with the given time-stamp in the data source.
List< LabelBoost > GetLabelBoosts(int nProjectId, bool bSort=true, int nSrcId=0)
Returns a list of all label boosts set on a project.
Database()
The Database constructor.
string GetSourceName(int nID, ConnectInfo ci=null)
Returns the name of a data source given its ID.
int PutRawImageMean(SimpleDatum sd, bool bUpdate, int nSrcId=0, ConnectInfo ci=null)
Save the SimpleDatum as a RawImageMean in the database.
string GetLabelCountsAsText(int nSrcId=0, ConnectInfo ci=null)
Returns the label counts for a given data source.
List< RawImage > ReindexRawImages(Log log, CancelEvent evtCancel, int nSrcId=0)
Reindex the RawImages of a data source.
void SaveChanges()
Saves any changes on the open satabase.
List< Dataset > GetAllDatasets(int nDatasetGroupID)
Returns a list of all datasets within a group.
void DeleteLabels(int nSrcId=0)
Delete the labels of a data source from the database.
void DeleteRawImageGroups()
Deletes all RawImage groups
void UpdateLabelCounts(Dictionary< int, int > rgCounts, DNNEntities entities)
Updates the label counts in the database for the open data source.
void UpdateBoost(long nImageID, int nBoost)
Update the image boost of a given image.
int PutRawImage(int nIdx, SimpleDatum d, string strDescription=null)
Save a SimpleDatum as a RawImage in the database.
int GetImageCount(int nSrcId=0, bool bActive=true, bool bInactive=true, ConnectInfo ci=null)
Get the number of images in the source.
void UpdateBoosts(int nSrcId, DateTime dtStart, DateTime dtEnd, int nBoost)
Update the boost of all images between a date range.
Label FindLabelInCache(int nLabel)
Search for a Label in the label cache.
bool CopyImageMean(int nSrcIdSrc, int nSrcIdDst, ConnectInfo ci=null)
Copy the raw image mean from one source to another.
Source GetSource(int nID, ConnectInfo ci=null)
Returns the Source entity given a data source ID.
int PutRawImageResultExtraData(int nRawImageResultID, byte[] rgExtraData)
Set the raw image result extra data field.
List< RawImage > QueryRawImages(params int[] rgSrcId)
Returns the list of raw images that have a source ID from a selected list.
void PutRawImageParameters(List< ParameterData > rgParam, ConnectInfo ci=null)
Save a list of raw image parameters.
void UpdateDatasetRelabel(int nDsID, bool bRelabel)
Update the dataset relabel flag for a dataset.
DateTime GetFirstTimeStamp(int nSrcId=0, string strDesc=null)
Returns the first time-stamp in the data source.
DateTime GetLastTimeStamp(out int nIndex, int nSrcId=0, string strDesc=null)
Returns the last time-stamp and index in the data source.
byte[] GetRawImageDataCriteria(int nImgID, int? nOriginalSourceID=null)
Queries the Data Criteria for an image an Converts the raw image data criteria data which may be stor...
string GetRawImageParameter(int nRawImageID, string strName, string strDefault)
Return the string value of a RawImage parameter.
int GetModelGroupID(string strGroup)
Retruns the ID of a model group given its name.
byte[] GetRawImageData(RawImage img, bool bLoadDataCriteria, bool bLoadDebugData, out byte[] rgDataCriteria, out int? nDataCriteriaFmtId, out byte[] rgDebugData, out int? nDebugDataFmtId)
Returns the raw data of the RawImage.
void DeleteRawImageMeans(int nSrcId=0)
Delete all RawImageMeans for a data source.
void UpdateActiveLabelByID(int nID, int nLabel)
Update the label value of a label.
Dataset GetDataset(string strTestingSrc, string strTrainingSrc)
Returns the Dataset entity containing the training and testing source names.
string FindDatasetNameFromSourceName(string strTrainSrc, string strTestSrc)
Searches for the data set name based on the training and testing source names.
string GetDatabaseFilePath(string strName)
Query the physical database file path.
DatasetGroup GetDatasetGroup(int nGroupID, ConnectInfo ci=null)
Returns the DatasetGroup entity given a group ID.
int GetSourceParameter(string strName, int nDefault, int nSrcId=0)
Return the data source parameter as an int.
List< Dataset > GetAllDatasetsWithCreator(int nDsCreatorID, bool? bRelabeled=null)
Returns a list of all datasets within a group with dataset creators.
string GetDatasetParameter(int nDsId, string strName)
Returns the value of a dataset parameter as a string.
void UpdateLabelBoost(int? nTgtLbl, bool bTgtLblExact, int? nTgtBst, bool bTgtBstExact, int? nNewLbl, int? nNewBst, params int[] rgSrcId)
Update the label and boost for a given search target criteria.
virtual string getImagePath(string strSrcName=null)
Returns the base image path used when saving binary data to the file system.
bool WaitForFileWriter(int nWait=int.MaxValue)
Wait for the file writer to complete writing all files.
DateTime GetDatasetMinimumTimestamp(int nDsID)
Returns the minimum time-stamp for a dataset.
void DeleteRawImageResults(int nSrcId=0)
Delete all RawImageResults for a data source.
int PutRawImageGroup(RawImageGroup g)
Adds a RawImageGroup to the database.
Specifies a database item used when querying boosted items.
int ID
Specifies the image ID.
int Boost
Specifies the image boost.
int id
Specifies the image ID used within the lambda statement.
int VirtualID
Specifies the image VirtualID (if any).
DateTime? time
Specifies the image time within the lambda statement.
string Desc
Specifies the image description.
int Index
Specifies the image index.
DateTime Time
Specifies the image time.
bool Active
Specifies whether or not the item is active.
int? OriginalSourceID
Specifies the original source ID.
object Tag
Get/set a user defined item.
bool? active
Specifies the active state used within the lambda statement.
int? index
Specifies the image index used within the lambda statement.
DbItem Clone()
Create a copy of the DbItem.
int? virtualid
Specifies the image VirtualID used within the lambda statement.
int? originalsrcid
Specifies the original source id used within the lambda statement.
int? label
Specifies the image label used within the lambda statement.
int? boost
Specifies the image boost used within the lambda statement.
string desc
Specifies the image description used within the lambda statement.
int Label
Specifies the image label.
override string ToString()
Returns the string representation of the DbItem.
The EntitiesConnection class defines how to connect to the database via Entity Frameworks.
static DNNEntities CreateEntities(ConnectInfo ci=null)
Returns the DNNEntities to use.
static ConnectInfo GlobalDatabaseConnectInfo
Get/set the global database connection info.
The ParameterData class is used to save and retrieve parameter data.
int SourceID
Specifies the source ID that the images belong to.
bool OnlyAddNew
Returns whether or not to only add the parameter if it does not exist.
int ImageID
When specified, returns the RawImage ID from which the parameter is to be queried or is associated,...
string Value
Returns the parameter value.
ParameterData(string strName, int nImageID)
The ParameterData constructor.
string Name
Returns the parameter name.
double? NumericValue
Returns the parameter numeric value.
byte[] Data
Returns the raw data associated with the parameter.
ParameterData(string strName, string strValue, double? dfVal=null, byte[] rgData=null, int nImageID=0, bool bOnlyAddNew=false, int nSrcId=0)
The ParameterData constructor.
The descriptors namespace contains all descriptor used to describe various items stored within the da...
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
@ NONE
No training category specified.
The MyCaffe.db.image namespace contains all image database related classes.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...