Skip to content

Commit

Permalink
Merge pull request #358 from NaturalSolutions/development
Browse files Browse the repository at this point in the history
Development: merge
  • Loading branch information
romfabbro authored Oct 14, 2016
2 parents 8811c80 + 6ae92f4 commit dde4215
Show file tree
Hide file tree
Showing 56 changed files with 1,639 additions and 646 deletions.
44 changes: 44 additions & 0 deletions Back/database/Pipe/DB_Mother/095_Up_Conf_protcole.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@


UPDATE f SET InputType = 'GridFormEditor',Options = '{"protocoleType":'+Options+',"nbFixedCol":0,"delFirst":0,"showLines":0}'
FROM [ModuleForms] f
where Options in (214,222) and InputType like '%listof%' and module_id = 1

Update f SET FieldSizeDisplay= 3, FieldSizeEdit = 3
FROM ModuleForms f
WHERE TypeObj = 222 and module_id = 1
AND Name = 'sampled'

Update f SET FieldSizeDisplay= 5, FieldSizeEdit = 5
FROM ModuleForms f
WHERE TypeObj = 222 and module_id = 1
AND Name = 'Measured_by'


Update f SET FieldSizeDisplay= 4, FieldSizeEdit = 4
FROM ModuleForms f
WHERE TypeObj = 222 and module_id = 1
AND Name = 'Egg_code'



Update f SET FieldSizeDisplay= 4, FieldSizeEdit = 4
FROM ModuleForms f
WHERE TypeObj = 214 and module_id = 1
AND Name = 'frequency'

Update f SET FieldSizeDisplay= 5, FieldSizeEdit = 5
FROM ModuleForms f
WHERE TypeObj = 214 and module_id = 1
AND Name in ('sex','age','signal')


Update f SET Options = 2010086
FROM ModuleForms f
WHERE module_id = 1 and TypeObj = 231 and Name = 'sex'


INSERT INTO [dbo].[TVersion] (TVer_FileName,TVer_Date,TVer_DbName) VALUES ('95_Up_Conf_protcole',GETDATE(),(SELECT db_name()))


GO
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

ALTER TABLE [ecoReleve_Sensor].[dbo].[T_argosgps]
ALTER COLUMN [type] varchar (20) not NULL
GO

UPDATE [ecoReleve_Sensor].[dbo].[T_argosgps] SET type = 'argos'
WHERE type ='arg'
GO



INSERT INTO [dbo].[TVersion] (TVer_FileName,TVer_Date,TVer_DbName) VALUES ('96_ecoReleve_Sensor_Up_type_argos',GETDATE(),(SELECT db_name()))


GO
112 changes: 112 additions & 0 deletions Back/database/Pipe/DB_Mother/097_Up_SP_validate_ALL_RFID.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@


ALTER PROCEDURE [dbo].[sp_validate_ALL_rfid]
@freq int,
@user int,
@nb_insert int OUTPUT,
@error int OUTPUT,
@exist int OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

DECLARE @data_to_insert table ( PK_id int
, FK_ind int
, FK_Sensor int
, chip_code varchar(10)
, date_ datetime
, lat decimal(9,5)
, lon decimal(9,5)
,ele int
,freq int );
Declare @data_duplicate table (
PK_id int

);

-- Gather not validated data.
WITH data AS (
SELECT ID
, FK_Sensor
, chip_code
, date_
,validated
,checked
, FK_MonitoredSite
, ROW_NUMBER() OVER (PARTITION BY FK_Sensor, chip_code, CONVERT(DATE, date_), DATEPART(hour, date_), DATEPART(minute, date_)/@freq ORDER BY date_) as r
FROM VRfidData_With_equipSite where checked = 0
)
INSERT INTO @data_to_insert
( PK_id
, FK_Sensor
, chip_code
, date_
, lat
, lon
,freq
,ele)
SELECT data.ID
, data.FK_Sensor
, data.chip_code
, data.date_
, lat
, lon
,@freq
,ele
FROM data
JOIN MonitoredSitePosition p
ON p.FK_MonitoredSite = data.FK_MonitoredSite AND p.StartDate <= data.date_
WHERE not exists (SELECT * FROM MonitoredSitePosition p1
WHERE p.FK_MonitoredSite = p1.FK_MonitoredSite AND p1.StartDate > p.StartDate AND p1.StartDate <= data.date_ )
and data.FK_MonitoredSite is not null AND data.r = 1 AND data.validated = 0 and data.checked=0;

UPDATE d SET FK_ind = iv.FK_Individual
FROM @data_to_insert d
JOIN IndividualDynPropValue iv
ON d.chip_code = iv.ValueString AND iv.FK_IndividualDynProp = 7 AND iv.StartDate <= d.date_
WHERE NOT EXISTS (
SELECT * FROM IndividualDynPropValue iv2
WHERE iv.FK_Individual = iv2.FK_IndividualDynProp AND iv.FK_IndividualDynProp = iv2.FK_IndividualDynProp
AND iv2.StartDate > iv.StartDate AND iv2.StartDate <= d.date_)

insert into @data_duplicate
SELECT d.PK_id
FROM @data_to_insert d JOIN Individual_Location loc
ON d.FK_ind = loc.FK_Individual and d.date_ = loc.Date and d.FK_Sensor = loc.FK_Sensor

-- Insert only the first chip lecture per RFID, per individual, per hour.
INSERT INTO Individual_Location (creator, FK_Sensor, FK_Individual, type_, Date, lat, lon, creationDate,FK_Region,ELE,OriginalData_ID)
SELECT @user, FK_Sensor, FK_ind, 'rfid', date_, lat, lon, CURRENT_TIMESTAMP,NULL,ele,'T_rfid_'+CONVERT(Varchar,d.PK_id)
FROM @data_to_insert d WHERE d.PK_id NOT IN (SELECT * FROM @data_duplicate)



-- Update inserted data.
UPDATE VRfidData_With_equipSite SET validated = 1 , frequency= @freq
WHERE VRfidData_With_equipSite.ID IN (SELECT PK_id FROM @data_to_insert);
UPDATE VRfidData_With_equipSite SET checked = 1 Where checked = 0



SELECT @nb_insert = COUNT(*) FROM @data_to_insert where PK_id not in (select * from @data_duplicate)
Select @exist = Count (*) from @data_duplicate
SELECT @error = @@ERROR

RETURN
END




GO





INSERT INTO [dbo].[TVersion] (TVer_FileName,TVer_Date,TVer_DbName) VALUES ('97_Up_SP_validate_ALL_RFID',GETDATE(),(SELECT db_name()))


GO
113 changes: 113 additions & 0 deletions Back/database/Pipe/DB_Mother/098_Up_SP_validate_RFID.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@



ALTER PROCEDURE [dbo].[sp_validate_rfid]
@IdEquip int,
@freq int,
@user int,
@nb_insert int OUTPUT,
@error int OUTPUT,
@exist int OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

DECLARE @data_to_insert table ( PK_id int
, FK_ind int
, FK_Sensor int
, chip_code varchar(10)
, date_ datetime
, lat decimal(9,5)
, lon decimal(9,5)
,ele int
,freq int );
Declare @data_duplicate table (
PK_id int

);

-- Gather not validated data.
WITH data AS (
SELECT ID
, FK_Sensor
, chip_code
, date_
,validated
,checked
, FK_MonitoredSite
, ROW_NUMBER() OVER (PARTITION BY FK_Sensor, chip_code, CONVERT(DATE, date_), DATEPART(hour, date_), DATEPART(minute, date_)/@freq ORDER BY date_) as r
FROM VRfidData_With_equipSite where equipID = @IdEquip
)
INSERT INTO @data_to_insert
( PK_id
, FK_Sensor
, chip_code
, date_
, lat
, lon
,freq
,ele)
SELECT data.ID
, data.FK_Sensor
, data.chip_code
, data.date_
, lat
, lon
,@freq
,ele
FROM data
JOIN MonitoredSitePosition p
ON p.FK_MonitoredSite = data.FK_MonitoredSite AND p.StartDate <= data.date_
WHERE not exists (SELECT * FROM MonitoredSitePosition p1
WHERE p.FK_MonitoredSite = p1.FK_MonitoredSite AND p1.StartDate > p.StartDate AND p1.StartDate <= data.date_ )
and data.FK_MonitoredSite is not null AND data.r = 1 AND data.validated = 0 and data.checked=0;

UPDATE d SET FK_ind = iv.FK_Individual
FROM @data_to_insert d
JOIN IndividualDynPropValue iv
ON d.chip_code = iv.ValueString AND iv.FK_IndividualDynProp = 7 AND iv.StartDate <= d.date_
WHERE NOT EXISTS (
SELECT * FROM IndividualDynPropValue iv2
WHERE iv.FK_Individual = iv2.FK_IndividualDynProp AND iv.FK_IndividualDynProp = iv2.FK_IndividualDynProp
AND iv2.StartDate > iv.StartDate AND iv2.StartDate <= d.date_)

insert into @data_duplicate
SELECT d.PK_id
FROM @data_to_insert d JOIN Individual_Location loc
ON d.FK_ind = loc.FK_Individual and d.date_ = loc.Date and d.FK_Sensor = loc.FK_Sensor

-- Insert only the first chip lecture per RFID, per individual, per hour.
INSERT INTO Individual_Location (creator, FK_Sensor, FK_Individual, type_, Date, lat, lon, creationDate,FK_Region,ELE,OriginalData_ID)
SELECT @user, FK_Sensor, FK_ind, 'rfid', date_, lat, lon, CURRENT_TIMESTAMP,dbo.fn_GetRegionFromLatLon(lat,lon),ele,'T_rfid_'+CONVERT(Varchar,d.PK_id)
FROM @data_to_insert d WHERE d.PK_id NOT IN (SELECT * FROM @data_duplicate)



-- Update inserted data.
UPDATE VRfidData_With_equipSite SET validated = 1 , frequency= @freq
WHERE VRfidData_With_equipSite.ID IN (SELECT PK_id FROM @data_to_insert);
UPDATE VRfidData_With_equipSite SET checked = 1 Where equipID = @IdEquip



SELECT @nb_insert = COUNT(*) FROM @data_to_insert where PK_id not in (select * from @data_duplicate)
Select @exist = Count (*) from @data_duplicate
SELECT @error = @@ERROR

RETURN
END



GO





INSERT INTO [dbo].[TVersion] (TVer_FileName,TVer_Date,TVer_DbName) VALUES ('98_Up_SP_validate_RFID',GETDATE(),(SELECT db_name()))


GO
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
UPDATE l SET OriginalData_ID = 'T_rfid_'+CONVERT(VARCHAR,r.ID)
FROM Individual_Location l
JOIN ecoReleve_Sensor.dbo.T_rfid r ON l.FK_Sensor = r.FK_Sensor AND l.Date = r.date_
WHERE l.OriginalData_ID is null and type_ = 'rfid'
GO


INSERT INTO [dbo].[TVersion] (TVer_FileName,TVer_Date,TVer_DbName) VALUES ('99_Up_Individual_Location_OriginalDataID_withRFID',GETDATE(),(SELECT db_name()))


GO
Loading

0 comments on commit dde4215

Please sign in to comment.