I am trying to access time from jfree.data and adding it to my results table in ImageJ. But this does not work and I don't know why. Here is my code:
// Set IJ settings
ResultsTable rt = new ResultsTable();
// create a series that automatically discard data > 30 seconds old...
TimeSeries intensities = new TimeSeries("Int");
intensities.setMaximumItemAge(30000);
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(intensities);
ImageProcessor ip;
//Run while Live
while (true) {
mm.live().snap(true);
ip = mm.live().getDisplay().getImagePlus().getProcessor();
ImageStatistics stats = ip.getStatistics();
intensities.add(new Millisecond(), stats.mean);
img = images.get(0);
rt.incrementCounter();
rt.addValue("Time",intensities.millisecond);
rt.addValue("Mean",stats.mean);
rt.show("Results");
Thread.sleep(10);
}
What am i doing wrong?
Here is some ImageJ-Java code I use for data entry to an ImageJ-Results table:
ResultsTable table = ResultsTable.getResultsTable( "myTable" );
if ( table == null )
table = new ResultsTable();
else
table.incrementCounter();
table.addValue( "Data", value );
table.show( "myTable" );
Related
I need to detect the number of customers who make purchases in the 2 stores with a single formula
data:
Result:
1 Person
Create this below measure-
person_count =
var total_shop_count = DISTINCTCOUNT(your_table_name[Shop])
var tab =
SUMMARIZE(
your_table_name,
your_table_name[Name],
"shop_count",DISTINCTCOUNT(your_table_name[Shop])
)
return
COUNTROWS(
FILTER(
tab,
[shop_count] = total_shop_count
)
)
Here is the output-
Below is the function that inserts my data.
using (SqlCommand insSwipeDataCommand = connection.CreateCommand())
{
insSwipeDataCommand.Transaction = transaction;
insSwipeDataCommand.CommandType = CommandType.StoredProcedure;
insSwipeDataCommand.CommandText = "dbo.insSwipeData_sp";
SqlParameter attendeeTableParam = insSwipeDataCommand.Parameters.Add("#AttendeeTable", SqlDbType.Structured);
attendeeTableParam.Value = this.dataTable;
attendeeTableParam.TypeName = "AttendeeTableType";
// add orgid parameter
insSwipeDataCommand.Parameters.Add("#orgId", SqlDbType.UniqueIdentifier).Value = this.organizationId;
insSwipeDataCommand.ExecuteNonQuery();
}
insSwipeData_sp
create PROC dbo.insSwipeData_sp
(#AttendeeTable AttendeeTableType READONLY
,#orgId UNIQUEIDENTIFIER
)
AS
BEGIN
SET NOCOUNT ON
DECLARE #enteredUserId UNIQUEIDENTIFIER
SET #enteredUserId = 'xxxxxxxxx-xxxx-xxx-xxxx-xxxxxxxxxx'
-- Delete old Swipe records
DELETE FROM dbo.swipeData_tbl
WHERE orgId = #orgId
-- CREATE Swipe Records
INSERT INTO dbo.swipeData_tbl
(orgId, sdid, rawData, enteredUserId, enteredUtc, manualEntry)
SELECT #orgId, attendeeId, barcode
,#enteredUserId, GETUTCDATE(), 0 -- Consider ( datepart , date ) if date here is needed as NVARCHAR
FROM #AttendeeTable
WHERE barcode IS NOT NULL and LTRIM(RTRIM(barcode)) <> '';
END
Here is an image of my AttendeeTableType schema.
and here is an image of my this.datatable that i am using for my attendeeTableParam
On the insSwipeDataCommand.ExecuteNonQuery(); line i get the following error.
The data for table-valued parameter "#AttendeeTable" doesn't conform to the table type of the parameter.
Per the error, your data does not conform to the table type exactly. Note "exactly" -- if you do not specify types for the columns, they will be inferred, and they can easily be inferred incorrectly. The best approach here is to create a table that you know matches the table type definition:
var dt = new DataTable();
dt.Columns.Add("firstName", typeof(string)).MaxLength = 100;
dt.Columns.Add("lastName", typeof(string)).MaxLength = 100;
dt.Columns.Add("studentId", typeof(string)).MaxLength = 10;
dt.Columns.Add("email", typeof(string)).MaxLength = 100;
dt.Columns.Add("barcode", typeof(string)).MaxLength = 100;
dt.Columns.Add("dob", typeof(string)).MaxLength = 200;
dt.Columns.Add("major", typeof(string)).MaxLength = 200;
dt.Columns.Add("gender", typeof(string)).MaxLength = 200;
dt.Columns.Add("classCode", typeof(string)).MaxLength = 15;
dt.Columns.Add("currentclassCode", typeof(string)).MaxLength = 15;
dt.Columns.Add("entranceCode", typeof(string)).MaxLength = 15;
dt.Columns.Add("attendeeId", typeof(Guid));
And then use .Clone() to create a new table with the correct schema when you need to insert data. This way, if you have a type or length mismatch, it will be caught on the client end.
There is another approach you can take that does not rely on embedding the table definition into the application, which is fetching it from the database. There are pros and cons to this -- it requires an extra roundtrip to the database and it's not as easy to spot mistakes in the application logic if the types or columns don't match, but it does give you additional flexibility to change the type without having to change the application (adding a new, nullable column, for example).
var dt = new DataTable();
using (var connection = new SqlConnection(...)) {
connection.Open();
using (var command = new SqlCommand()) {
command.Connection = connection;
command.CommandText = "DECLARE #t dbo.AttendeeTableType; SELECT * FROM #t;"
using (var reader = command.ExecuteReader()) {
dt.Load(reader);
}
}
}
Obviously you probably want to cache the results of this and .Clone(), rather than doing it for every command involving the table type parameter.
I reached this page while searching for similar issue that I was experiencing, but none of the replies did help me. After some head beating I found that the error is being generated in case when the data table being passed from the code has some data that does not match the TVP type specification.
For example if you defined the following type:
CREATE TYPE EmployeeType AS TABLE
(
EmpID BigInt, EmpName VARCHAR(100)
)
and suppose the data table that you are passing has (say) one EmpName that has more than 100 characters then "*** does not conform to table type" error is generated.
This solved my issue. Hope it will help others as well.
Even though Jeroen Mostert answer helped me solve one piece of the puzzle, this error was still popping up.
Here is what I learned;
Datatable created and passed as table value param should
correspond to the sequence / order of field in table value type defined
in sql.
So if your table type looks like below :
CREATE TYPE [dbo].[tvp_mytabletype] AS TABLE(
[ID] BIGINT,
[AddressCode] BIGINT,
[Address] NVARCHAR(200) NOT NULL
)
then define your DT with columns in exact same order/sequence like below :
DataTable dataTable = new DataTable();
//DataTable definition
dataTable.Columns.Add("ID", typeof(long));
dataTable.Columns.Add("AddressCode", typeof(long));
dataTable.Columns.Add("Address", typeof(string)).MaxLength = 200;
Your attendeeId is looks strange. It must be Guid in C# side.
I´m trying to optimize some process in my application but I´m stuck with this problem. My application is working so the entity mapping is correct. Simplifying what I´m trying to do is this:
using (var offCtx = new CheckinOfflineEntities())
{
using (var trans = offCtx.Database.BeginTransaction(IsolationLevel.Snapshot))
{
DateTime purgePivot = DateTime.Now.AddDays(-2);
count = offCtx.Database.ExecuteSqlCommand(#"select L.* into #NewLegs from InventoryLeg L where L.STDUTC >= {0}", purgePivot);
long d = offCtx.Database.SqlQuery<long>("select count(*) from #NewLegs").FirstOrDefault();
}
}
I´m selecting some data I want to delete from one table, storing it in a temporary table so that I can use this temporary table in other queries to exclude related data.
The problem is, when I try to use the temporary table I´m receiving the exception SqlException: "Invalid object name '#NewLegs'."
Thank you for your time.
You can merge the query like this.
And count returns int, not long.
COUNT always returns an int data type value. - MSDN
var query = string.Format("{0} {1}",
#"select L.* into #NewLegs from InventoryLeg L where L.STDUTC >= #STDUTC",
#"select count(*) from #NewLegs")
var d = offCtx.Database.SqlQuery<int>(query, new SqlParameter("STDUTC", purgePivot))
.FirstOrDefault();
I realy don´t know why but removing the parameter and adding it in the query solved the problem.
The code below works fine:
using (var offCtx = new CheckinOfflineEntities())
{
using (var trans = offCtx.Database.BeginTransaction(IsolationLevel.Snapshot))
{
DateTime purgePivot = DateTime.Now.AddDays(-2);
count = offCtx.Database.ExecuteSqlCommand(#"select L.* into #NewLegs from InventoryLeg L where L.STDUTC >= " + purgePivot.toString("yyyy-mm-dd HH:mm:ss");
long d = offCtx.Database.SqlQuery<long>("select count(*) from #NewLegs").FirstOrDefault();
}
}
I have a CSV file containing user info, say
first_name;last_name;user_id;full_name
column separator is ;, row terminator is \n.
What I need to do is to insert or update into users table. Unique key is user_id: if record with this user_id already exists, I need to update, if it doesn't I need to insert.
However, there are some problems that prevent me from using management studio data-import or bulk insert.
First, there are more fields in the users table (not just 4) and the order of columns in csv file does not correspond to the order of columns in the table. So I need to be able to specify which column from the file goes to which column in the table.
Secondly, some additional fields need to be filled. For example, users.email = users.user_id. Here is another obstacle - though for a newly inserted row users.email = users.user_id it is possible that users.email will change in the future, so I cannot just insert user_id and then run update [users] set [email] = [user_id].
Use fgetcsv
Example with two colonne :
<?php
$row = 0;
$update = "";
//separator of column
$separator = ";";
//creates two variables containing the index columns to read / modify
$idx_nom = 0;
$idx_rubrique = 1;
//Open file writing
if (($handle = fopen("test.csv", "r")) !== FALSE)
{
//we travel the file line by line, storing the data in a table
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE)
{
//can not control that the second line if the first contains the column headers
if ($row != 0)
{
//conditions of one column
if (stristr($data[$idx_nom], 'chemise'))
{
$data[$idx_rubrique] = 1;
}
else if (stristr($data[$idx_nom], 'costume'))
{
$data[$idx_rubrique] = 2;
}
else if (stristr($data[$idx_nom], 'cravate'))
{
$data[$idx_rubrique] = 3;
}
}
$update .= implode($separator,$data)."\r\n";
$row++;
}
fclose($handle);
}
//update from csv
$ouvre=fopen("test.csv","w+");
fwrite($ouvre,$update);
fclose($ouvre);
?>
var insertReq:SQLStatement = new SQLStatement();
insertReq.addEventListener(SQLErrorEvent.ERROR, dbErrorHandler);
insertReq.sqlConnection = conn;
insertReq.text = "INSERT INTO table1 (inputTime) VALUES (DATETIME('now'))";
insertReq.execute();
insertReq.text = "SELECT last_insert_rowid() as ID";
insertReq.execute();
var lastInsertId:int = insertReq.getResult().data[0].id;
trace(lastInsertId);
I made a local database and i am trying to insert some data but
I get lastInsertId zero?! Where I mess up things!?
You don't need to make additional execution of query for retrieving last inserted row's id.There is a built-in .lastInsertRowID property of SQLResult class for that purpose. Just use it like this:
var insertReq:SQLStatement = new SQLStatement();
insertReq.addEventListener(SQLErrorEvent.ERROR, dbErrorHandler);
insertReq.sqlConnection = conn;
insertReq.text = "INSERT INTO table1 (inputTime) VALUES (DATETIME('now'))";
insertReq.execute();
var lastInsertId:int = insertReq.getResult().lastInsertRowID;
trace(lastInsertId);