alert box through validation - cakephp-2.0

Is it possible with cakePHP 2.0 to have a field validated based on two other fields and still allow the user to go through with the submit?
Something like this, I have a form that has rate, term and credit tier. The rate is usually based on the term and credit tier like this, a credit tier of B and a term of 60 months will have a rate of 6.75%. But there will be instances where I want to have a rate of 5.25% for this same tier and term. Is there a way to alert the user that the rate does not match the tier and term combination but still allow the user to submit the rate the way it is? The rate, term, and tier will be stored in the database so that it can easily be changed as rates change.

Sure - in your model, define your own validation method and crunch your numbers in there. It might be better to pass your data in with $this->Form->hidden() than call other models while validating.

Related

How can we bring currencies to record level

Can you please explain how can we bring the manage currencies to record level. It was changing daily so can you please explain how it was being changed and how is it used in record level.
Your question is poorly worded. An opportunity that's worth €1000 and nobody edits it will still be worth €1000 tomorrow. What can change daily is currency exchange rate to $, £...
You can enable currency management (if not done already) which causes CurrencyIsoCode picklist to appear in every table. And then -if you really need to keep info what the price was at specific point in time - you can add support for "dated currency rates" on top of that. There are some considerations that out of the box the exchange rate recalculates only on Opportunity & related object. For your custom objects you'll need to write a nightly (hourly?) batch for example.
Once you're sure that dated rates is what you need (because maybe you need just the basic version with 1 current exchange rate) look into an integration that would periodically contact some currency exchange info server and write to either CurrencyType or DatedConversionRate

Star Schema Design for Social Media

I am new to dimensional modeling and have read a lot of material (star-schema, dimension/fact tables, SCD, Ralph Kimball's - The Data Warehouse Toolkit book, etc). So I have a good conceptual understanding of dimensional modeling constructs but finding it hard to apply to a usecase due to lack of experience and need some guidance.
Consider Twitter for example, I want to design a dimensional model to calculate -
DAU (Daily active users) = number of users who logged in and accessed twitter via website or mobile app on a given day
MAU (Monthly active users) = number of users who logged in and accessed twitter via website or mobile app in last 30 days including measurement date
User engagement = total(clicks + favorites + replies + retweets) on a tweet
These metrics over a period (like month) is the summation of these metrics on each day in that period.
I want to write SQLs to calculate these metrics for every quarter by region (eg: US and rest of world) and calculate year-over-year growth (or decline) in these metrics.
Eg:
Here are some details that I thought about -
Factless (transaction) fact table for user login activity with grain of 1 row per user per login : user_login_fact_schema (user_dim_key, date_dim_key, user_location_dim_key, access_method_dim_key)
Factless (transaction) fact table for user activity with grain of 1 row per user per activity : user_activity_fact_schema (user_dim_key, date_dim_key, user_location_dim_key, access_method_dim_key, post_key, activity_type_key)
Does this sounds correct? How should my model look like? What other dimensions/facts can I add here?
Wonder if I should collapse these 2 tables into 1 and have activity_type for logins as 'login', but there can be a huge number of logins without any activity so this will skew the data. Am I missing anything else?
Your model seems correct, it answers the questions on the graph you posted.
It could make sense to aggregate those two fact tables into one fact table joined with a "UserAction" dimension, mostly because a login can be interpreted as just another user action.
However, having separate fact tables focused on one metric (or process) may be preferable because it enables you to introduce measures/metrics into the tables, i.e. when your fact tables stop being factless. It also spares you a join with another dimension (UserAction) but that is becoming a bit less relevant these days, where storage and DB processing power are just getting cheaper.
You should keep the data on different tables to make sure you dont mix different grains.
user_login_fact_schema can be a materalized view based on user_activity_fact_schema filtering for activity type=login and including some logic to exclude duplicates (i.e. one login per user per day, if you are talking about daily active users)

Which kind of DBs calculate rate per minute statistics?

I have a use case requirement, where I want to design a hashtag ranking system. 10 most popular hashtag should be selected. My idea is something like this:
[hashtag, rateofhitsperminute, rateofhisper5minutes]
Then I will query, find out the 10 most popular #hashtags, whose rateofhits per minute are highest.
My question is what sort of databases, can I use, to provide me statistics like 'rateofhitsperminute' ?
What is a good way to calculate such a detail and store in it db ? Do some DBs offer these features?
First of all, "rate of hits per minute" is calculated:
[hits during period]/[length of period]
So the rate will vary depending on how long the period is. (The last minute? The last 10 minutes? Since the hits started being recorded? Since the hashtag was first used?)
So what you really want to store is the count of hits, not the rate. It is better to either:
Store the hashtags and their hit counts during a certain period (less memory/cpu required but less flexible)
OR the timestamp and hashtag of each hit (more memory/cpu required but more flexible)
Now it is a matter of selecting the time period of interest, and querying the database to find the top 10 hashtags with the most hits during that period.
If you need to display the rate, use the formula above, but notice it does not change the order of the top hashtags because the period is the same for every hashtag.
You can apply the algorithm above to almost any DB. You can even do it without using a database (just use a programming language's builtin hashmap).
If performance is a concern and there will be many different hashtags, I suggest using an OLAP database. OLAP databases are specially designed for top-k queries (over a certain time period) like this.
Having said that, here is an example of how to accomplish your use case in Solr: Solr as an Analytics Platform. Solr is not an OLAP database, but this example uses Solr like an OLAP DB and seems to be the easiest to implement and adapt to your use case:
Your Solr schema would look like:
<fields>
<field name="hashtag" type="string"/>
<field name="hit_date" type="date"/>
</fields>
An example document would be:
{
"hashtag": "java",
"hit_date": '2012-12-04T10:30:45Z'
}
A query you could use would be:
http://localhost:8983/solr/select?q=*:*&facet=true&facet.field=hashtag&facet.mincount=1&facet.limit=10&facet.range=hit_date&facet.range.end=2013-01-01T00:00:00Z&facet.range.start=2012-01-01T00:00:00
Finally, here are some advanced resources related to this question:
Similar question: Implementing twitter and facebook like hashtags
What is the best way to compute trending topics or tags? An interesting idea I got from these answers is to use the derivative of the hit counts over time to calculate the "instantaneous" hit rate.
HyperLogLog can be used to estimate the hit counts if an approximate calculation is acceptable.
Look into Sliding-Window Top-K if you want to get really academic on this topic.
No database has rate per minute statistics just built in, but any modern database could be used to create a database in which you could quite easily calculate rate per minute or any other calculated values you need.
Your question is like asking which kind of car can drive from New York to LA - well no car can drive itself or refuel itself along the way (I should be careful with this analogy because I guess cars are almost doing this now!), but you could drive any car you like from New York to LA, some will be more comfortable, some more fuel efficient and some faster than others, but you're going to have to do the driving and refueling.
You can use InfluxDB. It's well suited for your use case, since it was created to handle time series data (for example "hits per minute").
In your case, every time there is a hit, you could send a record containing the name of the hashtag and a timestamp.
The data is queryable, and there are already tools that can help you process or visualize it (like Grafana).
If you are happy with a large data set you could store and calculate this information yourself.
I believe Mongo is fairly fast when it comes to index based queries so you could structure something like this.
Every time a tag is "hit" or accessed you could store this information as a row
[Tag][Timestamp]
Storing it in such a fashion allows you to first of all run simple Group, Count and Sort operations which will lead you to your first desired ability of calculating the 10 most popular tags.
With the information in this format you can then perform further queries based on tag and timestamp to Count the amount of hits for a specific tag between the times X and Y which would give you your hits Per period.
Benefits of doing it this way:
High information granularity depending on time frames supplied via query
These queries are rather fast in mongoDB or similar databases even on large data sets
Negatives of doing it this way:
You have to store many rows of data
You have to perform queries to retrieve the information you need rather than returning a single data row

Time-dependent information: showing one rate and applying another

I have a situation where some information is valid only for a limited period of time.
One example is conversion rates stored in DB with validFrom and ValidTo timestamps.
Imagine the situation when user starts the process and I render a pre-receipt for him with one conversion rate, but when he finally hits the button other rate is already valid.
Some solutions I see for now:
Show user a message about new rate, render updated pre-receipt and ask him to submit form again.
To have overlaying periods of rates. So the transactions started with one rate could finish, but the new ones will start with the new rate.
While the 1st solution seems most logical, I've never seen such messages on websites. I wonder are there other solutions and what is the best practice.
So this is a question best posed to the product owner of your application. If I were wearing my product owner hat, I would want that the data being displayed never be out of sync, such that option (2) above never occurs. This is to make sure the display is fair in all respects.
Ways to handle this:
As you say: display an alert that something changed and allow a refresh.
handle updates to the data tables using DHTML/ AJAX updates so that the data is usually fresh.
To summarize: it's a business decision, but generally speaking it's a bad choice to show unfair and/or out of data data on a page.

Changing Currency on Site

I will be selling products on my site in GBP, however I would like an option for my customers to change currency to dollars and euros. This I know how to do but is there anyway to automatically fetch the data (currency rates) without manually changing it each day.
Also.
To avoid people tampering with the data on PayPal,which means that people can change the price to 1p. I put a security function:
if the price = fixed price then transaction approved.
However as the currency well keep changing is there anyway to get around that as well.
It's a bit of a tricky one.
If you accept payment in other currencies, you firstly have to show the price in that currency; this is not available as a feed or web service from PayPal (as far as I know). There are other feeds which provide this (Google is your friend - "currency conversion feed"), but they will never be exactly the same as PayPal.
The second issue is that - once you have taken payment in that currency - you don't know exactly how much you're going to get back in Pounds - say the sale happens today, but you only withdraw the money next week. The exchange rate could have shifted in that time, making your sale worth less in GBP. This risk could easily eat up your profits - especially in times of financial volatility.
The third issue is that currency conversion costs money - depending on volume and method, somewhere between 2 and 5%.
So, unless you're selling products with a very high margin, I'd be very nervous about taking payment in other currencies unless you can spend in those currencies too; if you can spend the money in foreign currencies, you don't have to pay for the conversion, and you are less exposed to the currency risk.
You can call out to a currency exchange web service.
I would suggest checking with your bank (whoever is behind your e-commerce site), as they may have a free tool for this.
Here is an example from a bank in New York -- it's a web service that will give you the exchange rate for any given date in xml format: http://www.ny.frb.org/markets/pilotfx.html
There is also the Google Finance API
http://code.google.com/apis/finance/docs/2.0/reference.html
This service is not free (I don't think), but looks pretty slick, and gives A LOT of infmormation via web service: http://www.xignite.com/forex/web-service/2000106.html

Resources