I'm working on an integration process that requires the currency conversion between a list of values in specific currency to a concrete given currency.
For this process will exists 2 files, one containing the exchange rates and other containing the prices with the origin currency.
The exchange rates files looks like this:
Text:USDtoEUR;Origin:USD;Destination:EUR;Value:0.7
Text:EURtoCAD;Origin:EUR;Destination:CAD;Value:0.5
The file containing the prices with the origin currency (and also the target currency) looks like this:
Index:0;TargetCurrency:CAD
Index:1;Description:Product1;Value:150;Currency:EUR
Index:2;Description:Product2;Value:3;Currency:USD
For this specific case there is no direct way to convert from USD to CAD, so I need to first convert it to another currency present in the file that has CAD exchange rate (EUR) and then convert it to CAD.
This is a very basic scenario, but I'm guessing those files can contain more complex ones, where maybe it's required to convert 2 or 3 times before reaching the target currency.
What I'm planning to do is to insert the content of the exchange rates file into a SQL Server table and then start a very manual process of looking records containing the target currency... but I've never faced this scenario and don't know if this could be an acceptable approach in terms of speed/performance, that's why I'm wondering if there is a standard algorithm or data structure best suited for this process.
I will appreciate your help
If you need to take the currency conversion rate into consideration to find an optimal conversion path, you would use Bellman-Ford Algorithm .
This link may help you.
But, if the performance of the conversion is matters, you need to use an algorithm to find the shortest path between two nodes (visiting fewer nodes, regardless of the conversion cost) like BFS or DFS
(means traversing the tree to find the shortest path between two nodes(two currencies).
I am trying to publish multiple ble advertisements in a UWP app in c#. I can add 2 manufactor data to one publisher and those will be transmitted. However if I want to publish more the data is not possible. Is this even possible?
Sample code so far:
var publisher = new BluetoothLEAdvertisementPublisher();
publisher.Advertisement.ManufacturerData.Add(CreateData("Test");
publisher.Advertisement.ManufacturerData.Add(CreateData("AnotherTest");
publisher.start();
BluetoothLEManufacturerData CreateData(string data)
{
var dataWriter = new DataWriter();
dataWriter.WriteInt32(data.Length);
dataWriter.WriteString(data);
return new BluetoothLEManufacturerData(0xFFFE, dataWriter.DetachBuffer());
}
Tried to add another manufactor data, but I get an exception
Tried multiple bluetooth adapters but windows don't seem to start the second adapter.
Also tried multiple Windows.Devices.Bluetooth.Advertisement.BluetoothLEAdvertisementPublisher but that also does not do the trick
We can put multiple manufacturer data in one BluetoothLE Advertisement. However, please note that the max length of an advertisement payload is 31 bytes.
Ref ADVERTISING AND SCAN RESPONSE DATA FORMAT (BLUETOOTH SPECIFICATION Version 4.0 [Vol 3] Page 375 )
The format of Advertising data and Scan Response data is shown in Figure
11.1. The data consists of a significant part and a non-significant part. The
significant part contains a sequence of AD structures. Each AD structure shall
have a Length field of one octet, which contains the Length value, and a Data
field of Length octets. The first octet of the Data field contains the AD type field. The content of the remaining Length - 1 octet in the Data field depends on the value of the AD type field and is called the AD data. The non-significant part extends the Advertising and Scan Response data when necessary and shall
contain all-zero octets.
BluetoothLEManufacturerData is one of these AD structures which AD Type is 0xFF.
For your first manufacturer data CreateData("Test"), its length is 1 (Lenght) + 1 (Type) + 2 (Company Id) + 8 (Your specific data), which is 12 bytes. And for the second manufacturer data, its length is 19 (1+1+2+15) bytes. With these two manufacturer data, the advertisement payload has already been 31 bytes. That's why you get an exception, when you try to add another manufacturer data. Actually, if you add one character in your date, for example using CreateData("Test=") instead of CreateData("Test"), you will also get the Invalid advertisement payload detected error.
So please make sure that the buffer length can fit within an advertisement payload. You can put multiple manufacturer data as long as its length is less than 31 bytes.
var publisher = new BluetoothLEAdvertisementPublisher();
publisher.Advertisement.ManufacturerData.Add(CreateData("T"));
publisher.Advertisement.ManufacturerData.Add(CreateData("A"));
publisher.Advertisement.ManufacturerData.Add(CreateData("S"));
publisher.start();
I am not sure whether i am asking an obvious question here. but i couldn't find any suitable variable for following case in HTML Variables for Paypal Payments Standard documentation.
1) How to configure extra attribute with own defined label to be shown on order summary page. Let say i would like to have: number of person: 2 Extra description: abcsd.
2) How to configure multiple tax of different label? The default i found is label with tax and only 1 tax?
GST: 10% Service Tax: 6%
Both of above seems to be a simple implementation to me, but i just couldn't find the solution using the documentation.
1) You can use the "custom" parameter to include any custom data you need to pass in the request. The field is literally called custom, and you can send up to 256 characters in this field.
2) Payments Standard only supports passing a single tax amount (that you calculate yourself) or a tax rate that would be calculated against the order amount. If you need to separate different tax rates/rules, you'll have to do that in your own shopping cart / order system.
This time, i come here just to see some opinios/view points.
I have a 'autocomplete' component that get from my server, the cities names of my country. At each city name typed on this component, it should go to my server a get some info.
Actually, how am I doing it?
At each letter typed on this component, it requests a list of cities that starts with this letter.
Obviously, that is no a good way to do it, because each request based just on a letter give me very similar lists.
Do you can think a better way to do it?
What is a better way? Do not make unecessary requests.
You could either preload all the city names locally (a country with 10,000 cities having an average name length of 11 bytes [10 single-byte characters + NUL] would require not much more than 110KB of space, depending on the method of storage [possibly something closer to 200KB?], so if you're okay with a [quite possibly very] small delay when loading the page and aren't worrying much about phone data limits, I'd suggest this), or you could have the city names be cached on the local machine, so while unique key combinations will result in server fetches, a repeated key combination in a later component will not.
I'm not really experienced with this aspect of programming, though, so I'm probably not the best person to give this sort of advice.
I'm working on a new project.
My best analogy would be a psychological evaluation test maker.
Aspect #1.
The end-business-user needs to create test questions. With question types. And possible responses to the questions when applicable.
Examples:
1. Do you have red hair? (T/F)
2. What is your favorite color? (Single Response/Multiple Choice)
(Possible Responses: Red, Yellow, Black, White)
3. What size shoe do you wear (rounded to next highest size)? (Integer)
4. How much money do you have on you right now? (Dollar Amount (decimal))
So I need to be able to create questions, their question type, and for some of the questions, possible answers.
Here:
Number 1 is a know type of "True or False".
Number 2 is a know type of "Single Response/Multiple Choice" AND the end-business-user will create the possible responses.
Number 3 is a known type of "Integer". The end-user (person taking the evaluation) can basically put in any integer value.
Number 4 is a known type of "Decimal". Same thing as Integer.
Aspect #2.
The end-business-user needs to evaluate the person's responses. And assign some scalar value to a set of responses.
Example:
If someone responded:
1. T
2. Red
3. >=8
4. (Not considered for this situation)
Some psychiatrist-expert figures out that if someone answered with the above responses, that you are a 85% more at risk for depression than the normal. (Where 85% is a number the end-business-user (psychiatrist) can enter as a parameter.
So Aspect #2 is running through someone's responses, and determining a result.
The "response grid" would have to be setup so that it will go through (some or all) the possibilities in a priority ranking order, and then after all conditions are met (on a single row), exit out with the result.
Like this:
(1.) T (2.) Red (3.) >=8 ... Result = 85%
(1.) T (2.) Yellow (3.) >=8 ... Result = 70%
(1.) F (2.) Red (3.) >=8 ... Result = 50%
(1.) F (2.) Yellow (3.) >=8 ... Result = 40%
Once a match is found, you exit with the percentage. If you don't find a match, you go to the next rule.
Also, running with this psych evaluation mock example, I don't need to define every permutation. A lot of questions of psych evaluations are not actually used, they are just "fluff". So in my grid above, I have purposely left out question #4. It has no bearing on the results.
There can also be a "Did this person take this seriously?" evaluation grid:
(3.) >=20 (4.) >=$1,000 ... Result = False
(The possibility of having a shoe size >= 20 and having big dollars in your pocket is very low, thus you probably did not take the psych test seriously.)
If no rule is found, (in my real application, not this mock up), I would throw an exception or just not care. I would not need a default or fall-through rule.
In the above, Red and Yellow are "worrisome" favorite colors. If your favorite color is black or white, it has no bearing upon your depression risk factor.
I have used Business Rule Engines in the past. (InRule for example).
They are very expensive, and it is not in the budget.
BizTalk Business Rules Framework is a possibility. Not de$irable, but possible.
My issue with any Rules-Engine is that the "vocabulary" (I have limited experience with business rules engines, mind you) is based off of objects, with static properties.
public class Employee
{
public string LastName
{ get; set; }
public DateTime HireDate
{ get; set; }
public decimal AnnualSalary
{ get; set; }
public void AdjustSalary(int percentage)
{
this.AdjustSalary= this.AdjustSalary + (this.AdjustSalary * percentage);
}
}
This would be easy to create business rules.
If
the (Employee's HireDate) is before (10 years ago)
then
(Increase Their Salary) By (5) Percent.)
else
(Increase Their Salary) By (3) Percent.)
But in my situation, the Test is composed of (dynamic) Questions and (dynamic) Responses, not predetermined properties.
So I guess I'm looking for some ideas to investigate on how to pull this off.
I know I can build a "TestMaker" application fairly quickly.
The biggest issue is integrating the Questions and (Possible Responses) into "evaluating rules".
Thanks for any tips.
Technologies:
DotNet 4.0 Framework
Sql Server 2008 Backend Database
VS2010 Pro, C#
If it's a small application, i.e 10s of users as opposed to 1000s, and its not business critical, then I would recommend Excel.
The advantages are, most business users are very familiar with excel and most probably have it on their machines. Basically you ship an Excel Workbook to your business users. They would enter the questions, the Type (Decimal, True False etc.). Click a button which triggers an excel macro. This could generate an XML configuration file or put the questions into SQL. Your application just reads it, displays it and collects responses as usual.
The main advantage of Excel comes in Aspect #2, the dynamic user chosen business rules. In another sheet of the same Excel document, the end business user can specify as many of the permutations of the responses/questions as they feel like. Excel users are very familiar with inputting simple formulas like =If(A1 > 20 && A2 <50) etc. Again the user pushes a button and generates either a configuration file or input the data into SQL server.
In your application you iterate through the Rules table and apply it to the responses.
Given the number of users/surveys etc. This simple solution would be much more simpler than biztalk or a full on customs rules engine. Biztalk would be good if you need to talk to multiple system, integrate their data, enforce rules, create work flow etc. Most of the other rules engines are also geared towards really big, complex rule system. The complexity in this rule systems, isn't just the number of rules or permutations, it is mostly having to talk to multiple system or "End dating" certain rules or putting in rules for future kick off dates etc.
In your case an Excel based or a similar datagrid on a webpage system would work fine. Unless of course you are doing a project for Gartner or some other global data survey firm or a major government statistical organisation. In that case I would suggest Biztalk or other commercial rules engines.
In your case, its SQL tables with Questions, Answer Types, Rules To Apply. Input is made user friendly via Excel or "Excel in the web" via a datagrid and then just iterate through the rules and apply them to the response table.
Are you sure you want to use a business rule engine for this problem?
As far as I understand it, the usecase for a BRE is
Mostly static execution flow
Some decisions do change often
In your usecase, the whole system (Q/A-flow and evaluation) are dynamic, so IMHO a simple domain specific language for the whole system would be a better solution.
You might want to take some inspiration from testMaker - a web based software exactly for this workflow. (Disclaimer: I contributed a bit to this project.) Its scoring rules are quite basic, so this might not help you that much. It was designed to export data to SPSS and build reports from there...
Be sure you are modeling a database suitable for hierarchical objects This article would help
create table for test
create tables for questions, with columns question, testid, questiontype
create tables for answers, answer id,question id, answer and istrue columns
answers belong to questions
one question can have many answer
create table for user or employee
create table for user answers, answer id, selected answer
evaluation (use object variables for boolean-integer coverage, use try catch before using function for high exception coverage.):
function(questiontype,answer,useranswer)
switch(questiontype) //condition can be truefalse, biggerthan,smallerthan, equals
{
case: "biggerthan": if(useranswer>answer) return true else return false;
case "truefalse": if(useranswer==answer) return true else return false
case "equals": if(useranswer==answer) return true else return false
}
get output as a data dictionary and post here please.
without a data schema the help you get will be limited.